您现在的位置是:主页 > news > 深圳地产网站建设/有哪些搜索引擎

深圳地产网站建设/有哪些搜索引擎

admin2025/6/6 0:01:59news

简介深圳地产网站建设,有哪些搜索引擎,宁波网站建设 联系哪家,做自媒体资源的网站1001. [WZOI2011 S3] 消息传递 ★★ 输入文件:messagew.in 输出文件:messagew.out 简单对比时间限制:1 s 内存限制:128 MB tarjan求强连通分量,判断该点所在的强连通分量中的点的个数,若该点所在的…

深圳地产网站建设,有哪些搜索引擎,宁波网站建设 联系哪家,做自媒体资源的网站1001. [WZOI2011 S3] 消息传递 ★★ 输入文件:messagew.in 输出文件:messagew.out 简单对比时间限制:1 s 内存限制:128 MB tarjan求强连通分量,判断该点所在的强连通分量中的点的个数,若该点所在的…

1001. [WZOI2011 S3] 消息传递

★★   输入文件:messagew.in   输出文件:messagew.out   简单对比
时间限制:1 s   内存限制:128 MB

 

tarjan求强连通分量,判断该点所在的强连通分量中的点的个数,若该点所在的强连通分量里的点的个数多于一个则说明出现了环,那么就会自己传递的信息再次传给自己、、

代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 210000
using namespace std;
bool vis[N];
int n,m,x,y,tot,sum,tim,top;
int dfn[N],low[N],ans[N],head[N],stack[N],belong[N];
int read()
{int x=0,f=1; char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}return x*f;
}
struct Edge
{int to,from,next;
}edge[N];
int add(int x,int y)
{tot++;edge[tot].to=y;edge[tot].next=head[x];head[x]=tot;
}
int tarjan(int now)
{dfn[now]=low[now]=++tim;stack[++top]=now,vis[now]=true;for(int i=head[now];i;i=edge[i].next){int t=edge[i].to;if(vis[t]) low[now]=min(dfn[t],low[now]);else if(!dfn[t]) tarjan(t),low[now]=min(low[now],low[t]);}if(dfn[now]==low[now]){sum++;belong[now]=sum;ans[sum]++;for(;stack[top]!=now;top--){int x=stack[top];vis[x]=false;belong[x]=sum,ans[sum]++;}top--,vis[now]=false;}
}
int main()
{freopen("messagew.in","r",stdin);freopen("messagew.out","w",stdout);n=read(),m=read();for(int i=1;i<=m;i++)x=read(),y=read(),add(x,y); for(int i=1;i<=n;i++)if(!dfn[i]) tarjan(i);for(int i=1;i<=n;i++)if(ans[belong[i]]>1) printf("T\n");else printf("F\n");return 0;
}

 

转载于:https://www.cnblogs.com/z360/p/7421201.html