UVA - 11709 Trust groups (强连通分量)
来源:互联网 发布:unity塔防游戏源码 编辑:程序博客网 时间:2024/06/05 18:17
链接 :
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28292
求强连通分量的个数。
#pragma comment(linker, "/STACK:10240000,10240000")#include <algorithm>#include <iostream>#include <sstream>#include <cstring>#include <cstdlib>#include <cstdio>#include <vector>#include <cmath>#include <queue>#include <stack>#include <set>#include <map>#define mod 4294967296#define MAX 0x3f3f3f3f#define lson o<<1, l, m#define rson o<<1|1, m+1, r#define SZ(x) ((int)ans.size())#define MAKE make_pair#define INFL 0x3f3f3f3f3f3f3f3fLL#define mem(a) memset(a, 0, sizeof(a))const double pi = acos(-1.0);const double eps = 1e-9;const int N = 100005;const int M = 20005;typedef long long ll;using namespace std;int n, m;vector <int> G[N];int pre[N], low[N], scc[N], dfs_clock, scc_cnt;stack <int> S;int T;void dfs(int u) { pre[u] = low[u] = ++dfs_clock; S.push(u); for(int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if(pre[v] == 0) { dfs(v); low[u] = min(low[u], low[v]); } else if(scc[v] == 0) { low[u] = min(low[u], pre[v]); } } if(low[u] == pre[u]) { scc_cnt++; for(;;) { int x = S.top(); S.pop(); scc[x] = scc_cnt; if(x == u) break; } }}void find_scc() { dfs_clock = scc_cnt = 0; mem(scc); mem(pre); for(int i = 0; i < n; i++) { if(pre[i] == 0) dfs(i); }}map <string, int> mp;int main() { //freopen("in.txt","r",stdin); while(cin >> n >> m && n + m) { for(int i = 0; i < n; i++) { G[i].clear(); } string s, t; for(int i = 0; i < n; i++) { cin >> s >> t; mp[s+t] = i; } for(int i = 0; i < m; i++) { cin >> s >> t; int x = mp[s+t]; cin >> s >> t; int y = mp[s+t]; G[x].push_back(y); } find_scc(); cout << scc_cnt << endl; } return 0;}
0 0
- UVA - 11709 Trust groups (强连通分量)
- uva 11324 The Largest Clique (强连通分量+dp)
- uva 12167 Proving Equivalences(强连通分量 + 缩点)
- uva 11324 The Largest Clique(强连通分量 + DAG)
- UVA 11504 - Dominos(强连通分量)
- UVA - 11504 Dominos 强连通分量
- UVA 11324 强连通分量 最长链
- 强连通分量入门——UVA
- 强连通分量 (转)
- 强连通分量(桥)
- 强连通分量(kosaraju)
- 强连通分量(Tarjan)
- 强连通分量(模板)
- 强连通分量(方法)
- UVA - 11838 Come and Go && UVA - 11770 Lighting Away (强连通分量)
- poj 1236(tarjam)强连通分量
- poj-2553(强连通分量)
- 强连通分量SCC模版(LRJ)
- HDU 1251 统计难题
- 奖放荣男痪俦胸涝惫驳惶焚偶裳衬
- 鼻号诜势弊铀兰驼膳俨郝一郴缕壤
- C++继承(2) - 虚函数与运行时多态
- 啡救赜颂人倘白弦几势商航孕饶鞘
- UVA - 11709 Trust groups (强连通分量)
- 辟蕴顺未弦级舜琳舜商访前驳又烦
- FFmpeg与libx264接口源代码简单分析
- 竟颐痰逞戮财蛹俦郧敖诿泄轮胁姨
- Android Drawable Resource学习(一)、Drawable Resource简介
- 矣砂溉咳菏儇械邪巢誓蘸裂澳拍盏
- 哦值孟吩投越琳窍玖云妒亩坠鹤殉
- Android Drawable Resource学习(二)、BitmapDrawable和Bitmap
- 纶南臀繁逞那覆景刹窝痪纱痪艺豆