poj 3352 边连通分量
思路与poj3177一模一样。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define Maxn 1010
#define Maxm Maxn*Maxn
#define inf 0x7fffffff
using namespace std;
int dfn[Maxn],low[Maxn],degree[Maxn],e,n,lab,index[Maxn];
struct Edge{
int to,from,next,v;
}edge[Maxm];
void init()
{
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(degree,,sizeof(degree));
memset(index,-,sizeof(index));
e=lab=;
}
void addedge(int from, int to)
{
edge[e].v=;
edge[e].from=from;
edge[e].to=to;
edge[e].next=index[from];
index[from]=e++;
edge[e].v=;
edge[e].from=to;
edge[e].to=from;
edge[e].next=index[to];
index[to]=e++;
}
void dfs(int u)
{
dfn[u]=low[u]=++lab;
int i,j,temp;
for(i=index[u];i!=-;i=edge[i].next)
{
temp=edge[i].to;
if(edge[i].v) continue;
edge[i].v=edge[i^].v=;
if(!dfn[temp])
{
dfs(temp);
low[u]=min(low[u],low[temp]);
}
low[u]=min(low[u],dfn[temp]);
}
}
int solve()
{
int i,j,temp=;
for(i=;i<=n;i++)
{
for(j=index[i];j!=-;j=edge[j].next)
{
if(low[i]!=low[edge[j].to])
degree[low[i]]++;
}
}
for(i=;i<=n;i++)
if(degree[i]==)
temp++;
return (temp+)/;
}
int main()
{
int m,i,j,a,b;
while(scanf("%d%d",&n,&m)!=EOF)
{
init();
for(i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
addedge(a,b);
}
dfs();
printf("%d\n",solve()); }
return ;
}
poj 3352 边连通分量的更多相关文章
- poj 3352 双连通分量
至少加几条边成为双连通分量 #include <iostream> #include <cstdio> #include <cstring> using names ...
- POJ 3352 (边双连通分量)
题目链接: http://poj.org/problem?id=3352 题目大意:一个连通图中,至少添加多少条边,使得删除任意一条边之后,图还是连通的. 解题思路: 首先来看下边双连通分量的定义: ...
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- POJ 3352 Road Construction(边—双连通分量)
http://poj.org/problem?id=3352 题意: 给出一个图,求最少要加多少条边,能把该图变成边—双连通. 思路:双连通分量是没有桥的,dfs一遍,计算出每个结点的low值,如果相 ...
- poj 3352 Road Construction(边双连通分量+缩点)
题目链接:http://poj.org/problem?id=3352 这题和poj 3177 一样,参考http://www.cnblogs.com/frog112111/p/3367039.htm ...
- POJ 3177 Redundant Paths & POJ 3352 Road Construction(双连通分量)
Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numb ...
- POJ 3352 Road Construction(边双连通分量,桥,tarjan)
题解转自http://blog.csdn.net/lyy289065406/article/details/6762370 文中部分思路或定义模糊,重写的红色部分为修改过的. 大致题意: 某个企业 ...
- POJ 3352 Road Construction (边双连通分量)
题目链接 题意 :有一个景点要修路,但是有些景点只有一条路可达,若是修路的话则有些景点就到不了,所以要临时搭一些路,以保证无论哪条路在修都能让游客到达任何一个景点 思路 :把景点看成点,路看成边,看要 ...
随机推荐
- 利用管道实现Shell多进程
shell中有个&,表示该程序在后台执行,其实是fork了一个子进程,跟系统调用是一样的. 在实际的操作过程中,有时需要控制后台程序的个数,毕竟启动太多的后台,会对服务的性能造成影响. 所以需 ...
- ocp 1Z0-042 121-178题解析
121. You want to create a new optimized database for your transactional production environment to be ...
- 树莓派加入定时任务实现花生壳定时重启(linux的定时任务)
由于花生壳在linux下不稳定,联系开机一个星期左右会挂掉,所以要使用定时任务实现每小时刷新一次/启动一次. 使用的是linux下的定时任务crontab去实现. 实现步骤: 1.编辑/etc/cro ...
- Unity3D之Mecanim动画系统学习笔记(五):Animator Controller
简介 Animator Controller在Unity中是作为一种单独的配置文件存在的文件类型,其后缀为controller,Animator Controller包含了以下几种功能: 可以对多个动 ...
- linux查看cpu、内存信息
#查看CPU信息(型号) cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # ...
- 使用WPF来创建 Metro UI程序
本文转载:http://www.cnblogs.com/TianFang/p/3184211.html 这个是我以前网上看到的一篇文章,原文地址是:Building a Metro UI with W ...
- cocos2d-x Mask的实现及优化
转自:http://blog.ch-wind.com/cocos2d-x%E4%B8%ADmask%E7%9A%84%E5%AE%9E%E7%8E%B0%E5%8F%8A%E4%BC%98%E5%8C ...
- C++ 对象没有显式初始化
C++ 对象没有显式初始化,结果是什么? 首先考虑非静态对象 1.方法内的局部对象: a.类类型:调用default构造方法 b.基本类型:值不确定 2.类中的数据成员: a.类类型:调用defaul ...
- TV
https://github.com/Xs4allWebTV/androidhttps://github.com/mode89/video-feedhttp://www.javaapk.com/sou ...
- HDU1013_Digital Roots【大数】【水题】
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...