XidianOJ 1072 National Disaster
Posted TOTOTOTOTZZZZZ
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XidianOJ 1072 National Disaster相关的知识,希望对你有一定的参考价值。
--正文
求无向图桥模板题
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> using namespace std; #define SIZE 10005 int dfn[SIZE],low[SIZE]; vector<int> link[SIZE]; int n,m; int res = 0,times = 0; void dfs(int u,int pre){ times ++; dfn[u] = times; low[u] = times; int i; for (i=0;i<link[u].size();i++){ int v = link[u][i]; if (v == pre) continue; if (dfn[v] == 0){ dfs(v,u); low[u] = min(low[u],low[v]); if (dfn[u] < low[v]) res ++; } else low[u] = min(low[u],dfn[v]); } } int main() { int time,T; scanf("%d",&T); for (time=1;time<=T;time++){ scanf("%d %d",&n,&m); res = 0; times = 0; memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); int i; for (i=0;i<n;i++){ link[i].clear(); } for (i=1;i<=m;i++){ int a,b; scanf("%d %d",&a,&b); link[a].push_back(b); link[b].push_back(a); } dfs(0,-1); printf("%d\\n",res); } return 0; }
以上是关于XidianOJ 1072 National Disaster的主要内容,如果未能解决你的问题,请参考以下文章