```cpp
#include<cstdio>
#include<algorithm>
#define N 10010
#define M 50010
using namespace std;
inline char gc(){
static char buf[1<<17],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<17,stdin),p1==p2)?EOF:*p1++;
}
template<class T>
inline bool read(T&n){
register char ch=gc();int sign=1;
for(n=0;(ch<'0'||ch>'9')&&ch!='-'&&ch!=EOF;ch=gc()); if(ch==EOF) return 0;
for(ch=='-'?ch=gc(),sign=-1:0;ch>='0'&&ch<='9';ch=gc()) n=(n<<1)+(n<<3)+ch-'0';n*=sign;return 1;
}
int head[N],nxt[M],to[M],s[N],scc[N],dfn[N],low[N],out[N],num[N],cnt,tim,tmp,ans,n,m,a,b,c;
bool instack[N];
void add(int f,int t){nxt[++cnt]=head[f],to[cnt]=t,head[f]=cnt;}
void tarjan(int u)
{
dfn[u]=low[u]=++tim;
s[++s[0]]=u;
instack[u]=1;
for(int e=head[u];e;e=nxt[e])
{
if(!dfn[to[e]])tarjan(to[e]),low[u]=min(low[u],low[to[e]]);
else if(instack[to[e]])low[u]=min(low[u],dfn[to[e]]);
}
if(dfn[u]==low[u])
{
int v;
scc[0]++;
do{
v=s[s[0]--];
instack[v]=0;
scc[v]=scc[0];
num[scc[0]]++;
}while(v!=u);
}
}
int main()
{
read(n),read(m);
for(int i=1;i<=m;i++)read(a),read(b),add(a,b);
for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
for(int i=1;i<=n;i++)
for(int e=head[i];e;e=nxt[e])if(scc[i]!=scc[to[e]])out[scc[i]]++;
for(int i=1;i<=scc[0]/*一开始打成scc[i]还有95....*/;i++)if(!out[i])tmp++,ans=i;
if(tmp==1)printf("%d",num[ans]);
else printf("0");
return 0;
}
```
数据也是够水
by W584102684 @ 2018-07-29 09:35:10
我一不小心写成这样
```
#define maxm
int u[2*maxm+7].....
```
35分。。。
by 览遍千秋 @ 2018-07-30 20:41:59
$45678$ 考古!
这里以后会布满考古者的足迹!
by Alex_Wei @ 2019-09-03 22:47:00
$\textsf{2020第一铲}$
by int114514 @ 2020-08-15 11:18:54
2021第一铲
by 匿名考古家 @ 2021-01-09 12:12:13
考古45678
by 扫雷王子 @ 2022-07-13 09:13:01
考古
by _DX3906_ @ 2022-08-10 11:17:39
2023第一铲
by Balor @ 2023-06-20 13:37:57