#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
struct edge{
int w,next;
}e[50000];
stack <int> s;
int n,m,cnt=1,ans;
int head[50000],d[50000];
void adde(int u,int w)
{
e[cnt].w=w;
e[cnt].next=head[u];
head[u]=cnt++;
d[w]++;
}
bool topsort()
{
for(int i=1;i<=n;i++)
if(!d[i]) s.push(i);
while(!s.empty())
{
int k=s.top();s.pop();
ans++;
for(int u=head[k];u!=-1;u=e[u].next)
{
d[e[u].w]--;
if(!d[e[u].w]) s.push(e[u].w);
}
}
if(ans==n) return 1;
else return 0;
}
int main()
{
int u,w,v;
memset(head,-1,sizeof(head));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)//建图
{
scanf("%d%d",&u,&w);
adde(u,w);
}
if(topsort())
{
printf("o(∩_∩)o");
}
else
{
printf("T_T\n");
printf("%d",n - ans);
}
return 0;
}
2833 奇怪的梦境 【解题报告】
最新推荐文章于 2025-08-15 11:59:55 发布