Tarjan求极大强连通分量模板

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<stack>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<cmath>
 8 using namespace std;
 9 struct data
10 {
11     int from,to,next,w;
12     data(){from=to=next=w=-1;}
13 }e[200];
14 int time=0;
15 int vis[200],head[200],low[200],dfsn[200];
16 int cnt;
17 void add(int u,int v,int w){e[cnt].from=u,e[cnt].to=v,e[cnt].next=head[u],e[cnt].w=w,head[u]=cnt,cnt++;}
18 int lu[200][200];
19 int tot;
20 stack<int> q;
21 void dfs(int now)
22 {
23     low[now]=dfsn[now]=time++;
24     vis[now]=1;
25     q.push(now);
26     for(int i=head[now];i>=0;i=e[i].next)
27     {
28         if(vis[e[i].to]) low[now]=min(low[now],dfsn[e[i].to]);
29         else
30         {
31             dfs(e[i].to);
32             low[now]=min(low[now],low[e[i].to]);
33         }
34     }
35     if(low[now]==dfsn[now])
36     {
37         int s=0;
38         do
39         {
40             tot++;
41             lu[tot][++s]=q.top();
42             vis[q.top()]=0;
43             q.pop();
44         }while(q.top()!=now);
45     }
46 }
47 int main()
48 {
49     memset(head,-1,sizeof(head));
50     
51 }
View Code
O(∩_∩)O~ (*^__^*) 嘻嘻…… O(∩_∩)O哈哈~
原文地址:https://www.cnblogs.com/wls001/p/5608610.html