本题大意:求一个无向图额割点的个数.
本题思路:建图之后打一遍模板.
1 /************************************************************************* 2 > File Name: uva-315.network.cpp 3 > Author: CruelKing 4 > Mail: 2016586625@qq.com 5 > Created Time: 2019年09月06日 星期五 17时15分07秒 6 本题思路:就是求图中有多少个割点 7 ************************************************************************/ 8 9 #include <cstdio> 10 #include <iostream> 11 #include <sstream> 12 #include <cstring> 13 #include <string> 14 using namespace std; 15 16 const int maxn = 100 + 5, maxm = maxn * maxn + 5; 17 int tot, head[maxn]; 18 19 struct Edge { 20 int to, next; 21 } edge[maxm]; 22 23 void init() { 24 memset(head, -1, sizeof head); 25 tot = 0; 26 } 27 28 void addedge(int u, int v) { 29 edge[tot] = (Edge) {v, head[u]}; head[u] = tot ++; 30 edge[tot] = (Edge) {u, head[v]}; head[v] = tot ++; 31 } 32 33 int n; 34 string str; 35 36 int dfn[maxn], low[maxn], stack[maxn]; 37 bool cut[maxn], instack[maxn]; 38 int Index, top, cut_num; 39 40 void tarjan(int u, int pre) { 41 dfn[u] = low[u] = ++ Index; 42 instack[u] = true; 43 stack[top ++] = u; 44 int son = 0; 45 for(int i = head[u]; ~i; i = edge[i].next) { 46 int v = edge[i].to; 47 if(!dfn[v]) { 48 son ++; 49 tarjan(v, u); 50 if(low[u] > low[v]) low[u] = low[v]; 51 if(pre != u && low[v] >= dfn[u]) { 52 cut[u] = true; 53 } 54 } else if(low[u] > dfn[v]) low[u] = dfn[v]; 55 } 56 if(u == pre && son > 1) { 57 cut[u] = true; 58 } 59 instack[u] = false; 60 top --; 61 } 62 63 void solve() { 64 memset(dfn, 0, sizeof dfn); 65 memset(low, 0, sizeof low); 66 memset(cut, false, sizeof cut); 67 Index = top = cut_num = 0; 68 for(int i = 1; i <= n; i ++) { 69 if(!dfn[i]) tarjan(i, i); 70 } 71 for(int i = 1; i <= n; i ++) if(cut[i]) cut_num ++; 72 printf("%d ", cut_num); 73 } 74 75 int main() { 76 int u, v; 77 while(~scanf("%d", &n) && n) { 78 init(); 79 while(scanf("%d", &u)) { 80 if(u == 0) break; 81 getline(cin, str); 82 stringstream ss; 83 ss << str; 84 while(ss >> v) addedge(u, v); 85 } 86 solve(); 87 } 88 return 0; 89 }