首页 > 代码库 > XidianOJ 1072 National Disaster
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。