This question many solution, I use Tarjan again to write again
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <
Stack> using namespace std;
const int MAXN = 2000;
int n,m,to[maxn<<1],head[maxn],cd[maxn],blt[maxn],nxt[maxn<<1],tot,scc[maxn],sz[maxn],tim=0;
BOOL Vis[maxn],flag = 0; struct Edge {int from,to;}
e[maxn<<1];
Stack <int> s;
void build (int f,int t) {To[++tot] = t;
Nxt[tot] = head[f];
HEAD[F] = tot;
int low[maxn],dfn[maxn],scccnt = 0;
void Dfs (int u) {low[u] = dfn[u] = ++tim;
S.push (U);
int V;
for (int i = head[u]; i = i = Nxt[i]) {v = to[i];
if (!dfn[v]) {DFS (v);
Low[u] = min (low[u],low[v]);
else if (!scc[v]) {Low[u] = min (low[u],dfn[v));
} if (low[u] = = Dfn[u]) {int x;
Scccnt + +;
while (!s.empty ()) {x = S.top ();
S.pop (); SCC[X] = scccnt;
sz[scccnt]++;
if (U = = x) break;
int main () {scanf ("%d%d", &n,&m);
for (int i = 1; I <= m + +) {scanf ("%d%d", &e[i].from,& e[i].to);
Build (E[i].from, e[i].to);
for (int i = 1; I <= n; i + +) if (!dfn[i]) DFS (i);
int ans = 0,q = 0;
int xx[5000];
for (int i = 1; I <= scccnt i + +) {if (sz[i]>1) {q + +;
XX[Q] = i;
for (int j = 1; j <= Q; j + +) for (int i = 1; I <= n; i + +) {if (scc[i] = = Xx[j])
{Vis[i] = 1;
for (int i = 1; I <= n; i + +) {if (Vis[i]) puts ("T");
Else puts ("F");
return 0; }