void topsort()
{
queue<int> q;
for(int i = 1; i <= n; i ++ )
if(!d[i])
{
q.push(i);
res.push_back(i);
}
while(q.size())
{
int t = q.front();
q.pop();
for(int i = h[t]; i != -1; i = ne[i])
{
int j = e[i];
if(--d[j] == 0)
{
q.push(j);
res.push_back(j);
}
}
}
}