The Code is as follows:
[Cpp]
# Include <iostream>
# Include <vector>
# Include <deque>
# Include <queue>
# Include <stack>
# Include <map>
# Include <set>
# Include <algorithm>
# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <string>
# Include <cmath>
Using namespace std;
Const int n= 210;
Typedef long LL;
Int n, m;
Int vis [N] [N], ru [N];
Void topsort ()
{
Int I, j, k = n;
Int cnt [N];
Priority_queue <int> q;
For (I = 1; I <= n; I ++)
If (ru [I] = 0)
Q. push (I );
While (! Q. empty ())
{
Int t = q. top ();
Q. pop ();
Cnt [t] = k --;
For (I = 1; I <= n; I ++)
{
If (vis [I] [t])
{
Ru [I] --;
If (ru [I] = 0)
Q. push (I );
}
}
}
If (k! = 0)
Printf ("-1 \ n ");
Else
{
For (I = 1; I <n; I ++)
Printf ("% d", cnt [I]);
Printf ("% d \ n", cnt [n]);
}
}
Int main ()
{
Int T;
Cin> T;
While (T --)
{
Memset (vis, 0, sizeof (vis ));
Memset (ru, 0, sizeof (ru ));
Scanf ("% d", & n, & m );
While (m --)
{
Int a, B;
Scanf ("% d", & a, & B );
If (vis [a] [B] = 0)
{// Weight
Vis [a] [B] = 1;
Ru [a] ++;
}
}
Topsort ();
}
Return 0;
}