poj 3352 Road Construction
// 只能说这题和上题一模一样
// 我就直接贴上题代码了、、 #include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MOD 1000000007
#define maxn 20100
#define maxm 5010
struct Edge{
int to;
int num;
int next;
Edge(){};
Edge(int u,int v){to=u;next=v;}
}E[maxn];
int V[maxm],num;
int pre[maxm];
int dfst,bcc;
int belong[maxm];
bool tag[maxn];
void init(int n){
dfst=;
num=;
bcc=;
for(int i=;i<=n;i++){
V[i]=-;
pre[i]=;
belong[i]=;
}
}
void add(int u,int v,int m){
E[num].to=v;
E[num].num=m;
E[num].next=V[u];
V[u]=num++; E[num].to=u;
E[num].num=m;
E[num].next=V[v];
V[v]=num++;
}
int dfs(int u,int fa){
int lowu;
lowu=pre[u]=++dfst;
int v,e;
for(e=V[u];e!=-;e=E[e].next){
v=E[e].to;
if(!pre[v]){
int lowv=dfs(v,u);
lowu=min(lowu,lowv);
if(lowv>pre[u]){
tag[E[e].num]=;
}
}
else if(v!=fa) lowu=min(lowu,pre[v]);
}
return lowu;
}
void dfsbcc(int u){
belong[u]=bcc;
int v,e;
for(e=V[u];e!=-;e=E[e].next){
if(tag[E[e].num]) continue;
v=E[e].to;
if(!belong[v]){
dfsbcc(v);
}
}
}
int rc[maxn][],in[maxm];
int main()
{
int F,R;
int u,v;
int i,j;
while(scanf("%d %d",&F,&R)!=EOF){
init(F);
for(i=;i<=R;i++){
scanf("%d %d",&u,&v);
rc[i][]=u;rc[i][]=v;
add(u,v,i);
tag[i]=;
}
dfs(,);
for(i=;i<=F;i++)
if(!belong[i]){
bcc++;
dfsbcc(i);
}
for(i=;i<=bcc;i++) in[i]=;
for(i=;i<=R;i++)
{
u=belong[rc[i][]];
v=belong[rc[i][]];
if(u!=v){
in[u]++;
in[v]++;
}
}
int ans=;
for(i=;i<=bcc;i++) if(in[i]==) ans++; printf("%d\n",(ans+)/); }
return ;
}
poj 3352 Road Construction的更多相关文章
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- 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(边双连通分量+缩点)
题目链接:http://poj.org/problem?id=3352 这题和poj 3177 一样,参考http://www.cnblogs.com/frog112111/p/3367039.htm ...
- POJ 3352 Road Construction 双联通分量 难度:1
http://poj.org/problem?id=3352 有重边的话重边就不被包含在双连通里了 割点不一定连着割边,因为这个图不一定是点连通,所以可能出现反而多增加了双连通分量数的可能 必须要用割 ...
- POJ 3352 Road Construction(边—双连通分量)
http://poj.org/problem?id=3352 题意: 给出一个图,求最少要加多少条边,能把该图变成边—双连通. 思路:双连通分量是没有桥的,dfs一遍,计算出每个结点的low值,如果相 ...
- 【边双连通】poj 3352 Road Construction
http://poj.org/problem?id=3352 [题意] 给定一个连通的无向图,求最少加多少条边使得这个图变成边双连通图 [AC] //#include<bits/stdc++.h ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction
这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...
- POJ - 3352 Road Construction(边双连通分支)
1.给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图. 2.POJ - 3177 Redundant Paths(边双连通分支)(模板) 与这道题一模一样.代码就改了下范围,其他都没动 ...
随机推荐
- unity3d结合轮廓显示,实现完整的框选目标(附Demo代码)
原地址:http://dong2008hong.blog.163.com/blog/static/469688272013111554511948/ 在unity里实现,其实很简单,因为有两个前提:1 ...
- 总结:Unity3D游戏上线后的流程回顾
原地址:http://unity3d.9tech.cn/news/2014/0127/39748.html 首先.unity 灯光烘焙 :Unity 3d FBX模型导入.选项Model 不导入资源球 ...
- Apache Ignite——新一代数据库缓存系统
[编者按]飞速增长的数据需要大量存储,对这些数据的管理也不是一件容易的事.但相比于存储和管理,如何处理数据才是开发人员真正的挑战.对于TB级别数据的存储和处理通常会让开发人员陷入速度.可扩展性和开销的 ...
- CentOS安装视频播放器SMPlayer
首先下载rpmforg,下载对应的版本,就是对应CentOS版本,还有32位与64位也要对应上.地址如下: http://wiki.centos.org/AdditionalResources/Rep ...
- hdu 1242 Rescue(BFS,优先队列,基础)
题目 /******************以下思路来自百度菜鸟的程序人生*********************/ bfs即可,可能有多个’r’,而’a’只有一个,从’a’开始搜,找到的第一个’r ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新,模板题,求区间和)
#include <iostream> #include <stdio.h> #include <string.h> #define lson rt<< ...
- Java 编译错误:缺少返回语句
示例: import java.util.*; import java.io.*; public class tt { public static void main(String[] args) { ...
- OpenCV源码阅读(3)---base.hpp
base.h处于core模块中,是OpenCV的核心类.其作用是定义了OpenCV的基本错误类型,在程序运行出现错误是抛出错误,防止数据溢出.总而言之,其功能主要是考虑程序的健壮性. 头文件 #ifn ...
- JUnit单元测试--小试牛刀
单元测试更多的是在开发阶段完成,开发人员每写一个函数的时候都会写相应的单元测试.对于java代码,普遍使用的是jUnit,根据jUnit可以自己相应的开发一套自动化测试框架.这个的前提是要学会juni ...
- BZOJ 1923 外星千足虫(高斯消元)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1923 题意:有n个数字,m次测试.每个数字为0或者1.每次测试选出一些数字出来把他们加起 ...