POJ,3177 Redundant Paths
来源:互联网 发布:linux apache压力测试 编辑:程序博客网 时间:2024/05/16 06:20
题意:奶牛要在n个牧场中转移,奶牛们厌倦了只有一条路可以走,所以请你来加最少的路,让牧场之间不止有一条固定的通路。
思路:构造双连通图的问题,可以看下面的文章了解一下概念:
https://www.byvoid.com/zhs/blog/biconnect
#include <iostream>#include <algorithm>#include <cstring>using namespace std;#define MAX 5000bool Map[MAX+10][MAX+10],vis[MAX+10];int low[MAX+10],dfn[MAX+10],value[MAX+10];int n,m;int c=0;void dfs(int u,int pre){ vis[u]=1; low[u]=dfn[u]=++c; for(int i=1;i<=n;i++) { if(Map[u][i]) { if(!vis[i]) { dfs(i,u); low[u]=min(low[u],low[i]); } else if(i!=pre) low[u]=min(low[u],dfn[i]); } }}int main(){ cin.sync_with_stdio(false); int temp1,temp2; while(cin>>n>>m) { memset(Map,0,sizeof(Map)); while(m--) { cin>>temp1>>temp2; Map[temp1][temp2]=Map[temp2][temp1]=1; } memset(vis,0,sizeof(vis));memset(low,0,sizeof(low));memset(dfn,0,sizeof(dfn));memset(value,0,sizeof(value)); c=0; dfs(1,1); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(Map[i][j]) if(low[i]!=low[j]) { value[low[j]]++; } int ans=count(value,value+n+1,1); cout<<(ans+1)/2<<'\n'; } return 0;}
0 0
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths
- *POJ 3177 Redundant Paths**
- poj 3177 Redundant Paths
- Redundant Paths POJ, 3177
- POJ 3177 Redundant Paths
- POJ 3177 Redundant Paths
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths
- POJ,3177 Redundant Paths
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths tarjan
- 架构师之DNS实战
- 多个图片宽度加起来100%但是不能在一行显示解决方案
- Gradle IDEA集成插件的使用
- 南洋oj 题目144小珂的苦恼
- 自定义EasyUI的datetimebox控件日期时间的显示格式
- POJ,3177 Redundant Paths
- kubernetes环境搭建
- Android与Linux的区别
- 使用ReentrantLock和Condition实现生产者消费者模型
- Android中两个Activity之间数据传递及返回
- 最长回文子串
- java 并发安全的思考
- hdu 1241 Oil Deposits (dfs经典入门)
- oracle插入数据报ORA-00001:违反唯一约束条件