记录编号 542332 评测结果 AAAAAAAAAA
题目名称 [WZOI 2011 S3] 消息传递 最终得分 100
用户昵称 Gravatarleon 是否通过 通过
代码语言 C++ 运行时间 0.796 s
提交时间 2019-09-23 19:10:47 内存使用 22.05 MiB
显示代码纯文本
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=200005;
  4. int top,cnt,qwq;
  5. int sum[maxn],vis[maxn],sta[maxn],head[maxn],tot,dfn[maxn],low[maxn],tmp,belong[maxn];
  6. struct _{int to,next;}a[maxn*2];
  7. void add(int x,int y){
  8. a[++tot].to=y;
  9. a[tot].next=head[x];
  10. head[x]=tot;}
  11. void tarjan(int x){
  12. sta[++top]=x;
  13. vis[x]=1;
  14. dfn[x]=low[x]=++cnt;
  15. for(int i=head[x];i;i=a[i].next){
  16. if(dfn[a[i].to]==0){
  17. tarjan(a[i].to);
  18. low[x]=min(low[x],low[a[i].to]);}
  19. else if(vis[a[i].to]==1)low[x]=min(low[x],dfn[a[i].to]);}
  20. if(dfn[x]==low[x]){
  21. qwq++;
  22. do{
  23. belong[sta[top]]=qwq;
  24. sum[qwq]++;
  25. vis[sta[top]]=0;}
  26. while(sta[top--]!=x);
  27. }}
  28. int main(){
  29. freopen("messagew.in","r",stdin);
  30. freopen("messagew.out","w",stdout);
  31. int n,m,q,w;
  32. cin>>n>>m;//n_dian m_bian
  33. for(int i=1;i<=m;i++){
  34. cin>>q>>w;
  35. add(q,w);}
  36. for(int i=1;i<=n;i++){
  37. if(dfn[i]==0)
  38. tarjan(i);}
  39. for(int i=1;i<=n;i++){
  40. if(sum[belong[i]]>=2)cout<<'T';
  41. else cout<<'F';
  42. }
  43. return 0;
  44. }