栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3630 Information

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3630 Information

#include <algorithm>#include <iostream>#include <cstring>#include <iomanip>#include <cstdlib>#include <string>#include <vector>#include <cstdio>#include <cmath>#include <map>using namespace std;int n, m;vector <int> e[101];bool visited[101];int dfn[101], low[101];vector <int> S;int idx;int DEL;int maxSCC;int res;void dfs(int cur){ visited[cur] = true; dfn[cur] = low[cur] = ++idx; S.push_back(cur); for(int i = 0; i < e[cur].size(); i++) { int t = e[cur][i]; if(t == DEL) continue; if(!visited[t]) { dfs(t); low[cur] = min(low[cur], low[t]); } else low[cur] = min(low[cur], dfn[t]); } if(dfn[cur] == low[cur]) { int thisSCC = 0; while(true) { int t = S[S.size()-1]; S.pop_back(); thisSCC ++; if(t == cur) { maxSCC = max(maxSCC, thisSCC); break; } } }}void tarjan(){ S.clear(); maxSCC = 0; memset(visited, false, sizeof(visited)); visited[DEL] = true; for(int i = 0; i < n; i++) if(!visited[i]) { idx = 0; dfs(i); } res = maxSCC; if(res == 1) res = 0;}int MAIN(){ while(cin >> n >> m) { for(int i = 0; i < n; i++) e[i].clear(); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; e[a].push_back(b); } int ans = 10000; for(int i = 0; i < n; i++) { DEL = i; tarjan(); ans = min(ans, res); } cout << ans << endl; } return 0;}int main(){ ios :: sync_with_stdio(false); return MAIN();}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375566.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号