​传送门​


#include<bits/stdc++.h>
#define N 1005
#define M 100005
using namespace std;
int first[N],next[M],to[M],tot;
int n,m,id[N],size[N],top,cnt;
int dfn[N],low[N],sta[N],insta[N],sign;
map<pair<int,int>,int> S;
int read(){
int cnt=0,f=1;char ch=0;
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch))cnt=cnt*10+(ch-'0'),ch=getchar();
return cnt*f;
}
void add(int x,int y){
next[++tot]=first[x],first[x]=tot,to[tot]=y;
}
void dfs(int u){
dfn[u]=low[u]=++sign;
sta[++top]=u,insta[u]=1;
for(int i=first[u];i;i=next[i]){
int t=to[i];
if(!dfn[t]) dfs(t),low[u]=min(low[u],low[t]);
else if(insta[t] && dfn[t]<low[u]) low[u]=dfn[t];
}
if(dfn[u]==low[u]){
cnt++;do{
id[sta[top]]=cnt,size[cnt]++,insta[sta[top]]=0;
}while(sta[top--]!=u);
}
}
int main(){
n=read(),m=read();
for(int i=1;i<=m;i++){
int x=read(),y=read();
if(!S[make_pair(x,y)]) S[make_pair(x,y)]=1,add(x,y);
}
for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i);
for(int i=1;i<=n;i++){
if(size[id[i]]==1) printf("F\n");
else printf("T\n");
}
return 0;
}