日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lightoj 1026 无向图 求桥

發布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lightoj 1026 无向图 求桥 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:http://lightoj.com/volume_showproblem.php?problem=1026

#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<queue> #include<vector> using namespace std; const int maxn = 10050; const int INF = 0x3f3f3f;vector<int> G[maxn]; int pre[maxn],dfs_clock,low[maxn];struct ANS{int l,r;bool operator < (const ANS& a) const{return l < a.l || (l == a.l && r < a.r); //排序被坑了,WA了好幾次啊,沒想后面的情況。 } }ans[maxn]; int cnt; int n;void tarjan(int u,int fa){low[u] = pre[u] = dfs_clock++;for(int i=0;i<G[u].size();i++){int v = G[u][i];if(v == fa) continue;if(!pre[v]){tarjan(v,u);low[u] = min(low[u],low[v]);if(low[v] > pre[u]){ans[cnt].l = min(u,v);ans[cnt].r = max(u,v);cnt++;}}elselow[u] = min(low[u],pre[v]); } }void init(){cnt = 0;dfs_clock = 1;memset(pre,0,sizeof(pre));for(int i=0;i<n;i++) G[i].clear(); } int main() {freopen("E:\\acm\\input.txt","r",stdin);int T;cin>>T;for(int t=1;t<=T;t++){scanf("%d",&n);init();for(int i=0;i<n;i++){int u,m;scanf("%d (%d)",&u,&m);for(int j=1;j<=m;j++){int v;scanf("%d",&v);G[u].push_back(v);}}for(int i=0;i<n;i++){if(!pre[i]){tarjan(i,-1);}}printf("Case %d:\n",t);printf("%d critical links\n",cnt);sort(ans,ans+cnt);for(int i=0;i<cnt;i++){printf("%d - %d\n",ans[i].l,ans[i].r);}} } View Code

?

轉載于:https://www.cnblogs.com/acmdeweilai/p/3265278.html

總結

以上是生活随笔為你收集整理的lightoj 1026 无向图 求桥的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。