比赛 |
20120809 |
评测结果 |
AAATTTTTTT |
题目名称 |
消息传递 |
最终得分 |
30 |
用户昵称 |
Truth.Cirno |
运行时间 |
7.701 s |
代码语言 |
C++ |
内存使用 |
115.59 MiB |
提交时间 |
2012-08-09 11:11:05 |
显示代码纯文本
#include <cstdio>
#include <memory.h>
using namespace std;
int ava=0,tow[100001],way[10000001],waynext[10000001],waylast[10000001],que[100001];
bool used[100001];
bool dup(int from,int to)
{
int poi=tow[from];
while (poi)
{
if (to==way[poi])
return(1);
poi=waynext[poi];
}
return(0);
}
void addway(int from,int to)
{
if (tow[from]==0)
{
tow[from]=++ava;
waylast[from]=ava;
way[ava]=to;
return;
}
int poi=waylast[from];
waynext[poi]=++ava;
waylast[from]=ava;
way[ava]=to;
}
int main(void)
{
freopen("messagew.in","r",stdin);
freopen("messagew.out","w",stdout);
int i,n,m,x,y,poi,head,tail;
bool done;
scanf("%d%d",&n,&m);
for (i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
if (!dup(x,y))
addway(x,y);
}
for (i=1;i<=n;i++)
{
done=false;
tail=0;
head=0;
que[0]=i;
memset(used,0,sizeof(used));
used[i]=true;
while (!done&&head>=tail)
{
poi=tow[que[tail]];
while (poi)
{
if (way[poi]==i)
{
done=true;
break;
}
else if (!used[way[poi]])
{
head++;
que[head]=way[poi];
if (!dup(i,way[poi]))
addway(i,way[poi]);
used[way[poi]]=true;
}
poi=waynext[poi];
}
tail++;
}
if (done)
printf("T\n");
else
printf("F\n");
}
return(0);
}