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(边双连通分支)(模板) 与这道题一模一样.代码就改了下范围,其他都没动 ...
随机推荐
- OWASP
开放式Web应用程序安全项目(OWASP,Open Web Application Security Project)是一个组织,它提供有关计算机和互联网应用程序的公正.实际.有成本效益的信息.其目的 ...
- uva 10887
是个 hash 用的容器类水过 #include <iostream> #include <cstdio> #include <string> #include ...
- soap 路由
下面主要通过项目实例来具体阐述如何实现wse路由和一些项目开发中的细节.本人水平有限,有不对的地方,请朋友们不吝赐教. 在开始项目之前,先了解一下路由的概念,所谓"路由",是指把数 ...
- ifram一些常用的知识点
本文摘自:http://www.cnblogs.com/duankaige/archive/2012/09/20/2695012.html iframe的调用包括以下几个方面:(调用包含html ...
- Android Service 的一些笔记
绑定服务: 用于间接调用服务里面的方法.如果调用者Activity被销毁了,服务也跟着销毁了,服务也会跟着销毁. 开启服务: 不可以调用服务里面的方法.如果调用者的Activity退出了,服务还会长期 ...
- mysql 多表 update sql语句总结
mysql 多表 update 有几种不同的写法. 假定我们有两张表,一张表为Product表存放产品信息,其中有产品价格列Price:另外一张表是ProductPrice表,我们要将ProductP ...
- web服务器、应用服务器、http服务器区别
引用 WEB服务器.应用程序服务器.HTTP服务器有何区别?IIS.Apache.Tomcat.Weblogic.WebSphere都各属于哪种服务器 Web服务器的基本功能就是提供Web信息 ...
- IDEA查找功能小结
查找类:Ctrl + N 支持模糊查询
- C++:运算符重载函数
5.运算符重载 5.1 在类外定义的运算符重载函数 C++为运算符重载提供了一种方法,即在运行运算符重载时,必须定义一个运算符重载函数,其名字为operator,后随一个要重载的运算符.例如,要重载& ...
- linux下,如何把整个文件夹上传到服务器(另一台linux)
1.Linux下目录复制:本机->远程服务器 scp -r /home/shaoxiaohu/test1 zhidao@192.168.0.1:/home/test2 #test1为源目录, ...