首页 > 学院 > 开发设计 > 正文

bzoj1051 [HAOI2006]受欢迎的牛

2019-11-10 19:21:51
字体:
来源:转载
供稿:网友

没做对

#include <bits/stdc++.h>#define N 50005using namespace std;stack <int> S;vector <int> E[N];int dfn[N],low[N];int p[N],h[N],s[N];int cnt = 0;int k = 0;int n,m;void tarjan(int x){ S.push(x); low[x] = dfn[x] = cnt++; for (int i = 0; i < E[x].size(); i++) { int v = E[x][i]; if (!dfn[v]) { tarjan(v); low[x] = min(low[x],low[v]); } else if(!s[v]) low[x] = min(low[x],dfn[v]); } if (dfn[x] == low[x]) { k++; while (true) { int now = S.top(); S.pop(); s[now] = k; h[k]++; if (now == x) break; } }}void rebuild(){ for (int i = 1; i <= n; i++) for (int j = 0; j < E[i].size(); j++) if (s[i] != s[E[i][j]]) p[s[i]]++;}int main(){ scanf("%d%d",&n,&m); for (int i = 1; i <= m; i++) { int x,y; scanf("%d%d",&x,&y); E[x].push_back(y); } for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i); rebuild(); int tot = 0,sav; for (int i = 1; i <= k; i++) if (!p[i]) tot++,sav=i; if (tot > 1) { PRintf("0/n"); } else printf("%d/n",h[sav]);}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表