poj 3352 Road Construction
来源:互联网 发布:辅助软件是什么意思 编辑:程序博客网 时间:2024/05/04 14:42
与poj 3177 类似,不过此题没有重边,所以可以用 vector 来存边。
#include<stdio.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;const int N=5000+5;int dfn[N],low[N];bool vis[N];vector<int> v[N]; //用vector 存边int n,m,cout;int cnt[N];void input(){ // memset(mp,0,sizeof(mp)); while(m--) { int a,b; scanf("%d%d",&a,&b); //if(find(v[a].begin(),v[a].end(),b)==v[a].end()) v[a].push_back(b); //if(find(v[b].begin(),v[b].end(),a)==v[b].end()) v[b].push_back(a); // mp[a][b]=mp[b][a]=1; }}void init(){ memset(vis,0,sizeof(vis)); memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(cnt,0,sizeof(cnt)); cout=0;}void tarjan(int x,int pre){ vis[x]=1; low[x]=dfn[x]=++cout; for(int i=0; i<v[x].size(); i++) { int e=v[x][i]; if(e==pre) continue; if(!dfn[e]) { tarjan(e,x); low[x]=min(low[x],low[e]); } else if(vis[e]) low[x]=min(low[x],dfn[e]); }}void sove(){ tarjan(1,1); for(int i=1; i<=n; i++) for(int j=0; j<v[i].size(); j++) //for(int j=1; j<=n; j++) { int e=v[i][j]; //if(mp[i][j]) if(low[i]!=low[e]) cnt[low[e]]++; } int ans=0; for(int i=1; i<=n; i++) { //printf("--%d--\n",cnt[i]); if(cnt[i]==1) ans++; } printf("%d\n",(ans+1)/2);}int main(){ //freopen("a.txt","r",stdin); while(~scanf("%d%d",&n,&m)) { input(); init(); sove(); }}
0 0
- poj 3352 Road Construction
- POJ 3352 Road Construction
- POJ 3352: Road Construction
- POJ 3352 Road Construction
- poj 3352 Road Construction
- poj 3352 Road Construction
- POJ 3352 Road Construction
- poj 3352 Road Construction
- POJ 3352 Road Construction
- POJ 3352 Road Construction
- poj 3352 Road Construction
- poj 3352 Road Construction
- POJ 3352 Road Construction
- POJ 3352 Road Construction解题报告
- [双连通分量]poj 3352 Road Construction
- poj-3352-Road Construction-缩点
- 【POJ】3352 Road Construction 边双连通
- POJ 3352 Road Construction(图论-tarjan)
- android中AudioRecord使用
- HDOJ-2795-Billboard 解题报告
- C# 添加引用问题(转)
- android_Socket
- 学生3门课的总分,平均分,最大值,最小值
- poj 3352 Road Construction
- sphinx分布式索引简介
- C++新手——关于引用遍历
- IOS 各类证书截图步骤
- 关于Rijndael算法的加密
- 顺序栈和链栈的基本操作
- ftp 配置
- UIPageControl
- Reader