[Cpp]
/* The meaning of the question is obscure. It is roughly the number of points with a degree of 0 after a thumbnail. */
# Include <stdio. h>
# Include <cstring>
# Include <vector>
# Include <iostream>
Using namespace std;
Vector <int> e [5010];
Int dfn [5001];
Int low [5001];
Int stack [5001];
Bool instack [5001];
Int belong [5001];
Int out [5001];
Int n, m, num, top, cnt;
Void tarjan (int u)
{
Int j;
Stack [top ++] = u;
Low [u] = dfn [u] = ++ num;
Instack [u] = true;
For (int I = 0; I <e [u]. size (); I ++)
{
Int v = e [u] [I];
If (! Dfn [v])
{
Tarjan (v );
Low [u] = min (low [v], low [u]);
}
Else if (instack [v])
Low [u] = min (dfn [v], low [u]);
}
If (low [u] = dfn [u])
{
Cnt ++;
Do
{
J = stack [-- top];
Instack [j] = false;
Belong [j] = cnt;
}
While (j! = U );
}
}
Int main ()
{
While (scanf ("% d", & n) = 1)
{
If (n = 0) break;
Scanf ("% d", & m );
Int a, B;
For (int I = 1; I <= n; I ++)
E [I]. clear ();
Top = 0;
Num = 0;
Cnt = 0;
While (m --)
{
Scanf ("% d", & a, & B );
E [a]. push_back (B );
}
Memset (low, 0, sizeof (low ));
Memset (dfn, 0, sizeof (dfn ));
Memset (instack, false, sizeof (instack ));
Memset (belong, 0, sizeof (belong ));
For (int I = 1; I <= n; I ++)
{
Out [I] = 0;
If (! Dfn [I])
Tarjan (I );
}
For (int I = 1; I <= n; I ++)
{
Int len = e [I]. size ();
For (int j = 0; j <len; j ++)
{
If (belong [I]! = Belong [e [I] [j])
Out [belong [I] ++;
} Www.2cto.com
}
Int k = 0;
For (int I = 1; I <= n; I ++)
{
If (out [belong [I] = 0)
{
If (k ++) printf ("");
Printf ("% d", I );
}
}
Printf ("\ n ");
}
Return 0;
}