POJ——T3352 Road Construction
http://poj.org/problem?id=3352



vis表示访问的次序 low的值相同的点在同一连通分量
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N();
int n,m,u,v,ans;
int head[N],sumedge;
struct Edge
{
int to,next;
Edge(int to=,int next=) :
to(to),next(next) {}
}edge[N<<]; void ins(int from,int to)
{
edge[++sumedge]=Edge(to,head[from]);
head[from]=sumedge;
} int tim,dfn[N],low[N],vis[N],du[N];
int sumcol,col[N],colvis[N]; void DFS(int now,int pre)
{
low[now]=dfn[now]=++tim;
vis[now]=;
for(int i=head[now];i;i=edge[i].next)
{
int go=edge[i].to;
if(go==pre) continue;
if(!vis[go])
{
DFS(go,now);
low[now]=min(low[now],low[go]);
} else if(vis[go]==)
low[now]=min(low[now],dfn[go]);
}
vis[now]=;
} int main()
{
scanf("%d%d",&n,&m);
for(;m;m--)
{
scanf("%d%d",&u,&v);
ins(u,v); ins(v,u);
}
for(int i=;i<=n;i++)
if(!vis[i]) DFS(i,i);
for(u=;u<=n;u++)
for(int j=head[u];j;j=edge[j].next)
{
v=edge[j].to;
if(low[u]!=low[v])
du[low[u]]++;
}
for(int i=;i<=n;i++)
if(du[i]==) ans++;
printf("%d\n",(ans+)>>);
return ;
}
POJ——T3352 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 ...
- POJ P3352 Road Construction 解题报告
P3352 Road Construction 描述 这几乎是夏季,这意味着它几乎是夏季施工时间!今年,负责岛屿热带岛屿天堂道路的优秀人士,希望修复和升级岛上各个旅游景点之间的各种道路. 道路本身也很 ...
- 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 3353 Road Construction tarjan 边双联通分支 缩点+结论
题意:一个连通的无向图,求至少需要添加几条边,救能保证删除任意一条边,图仍然是连通的. 链接:http://poj.org/problem?id=3352 思路:边的双连通图.其实就是要求至少添加几条 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction
这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...
- 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值,如果相 ...
随机推荐
- PHP下的异步尝试一:初识生成器
PHP下的异步尝试系列 PHP下的异步尝试一:初识生成器 PHP下的异步尝试二:初识协程 PHP下的异步尝试三:协程的PHP版thunkify自动执行器 PHP下的异步尝试四:PHP版的Promise ...
- 2019-03-22 Python Scrapy 入门教程 笔记
Python Scrapy 入门教程 入门教程笔记: # 创建mySpider scrapy startproject mySpider # 创建itcast.py cd C:\Users\theDa ...
- 小记如何有顺序的搭建一个Spring的web项目
如何有顺序的搭建一个Spring的web项目 一.新建一个简单的maven,war工程 eclipse下如有报错,右键 Deployment 单击 Generate 生成web.xml后可解决报错 二 ...
- 06001_NoSQL概述
1.什么是NoSQL? NoSQL(NoSQL=Not Only SQL),意即“不仅仅是SQL”,是一项全新的数据库理念,泛指非关系型的数据库. 2.关于关系型数据库和nosql数据库 (1)关系型 ...
- 使用Java语言实现,自己主动生成10个整数(1~100,求出生成数列中的最大值和最小值,不同意使用Arrays类的sort方法
这是考察主要的java基础,没啥难点,直接上代码,近期在准备面试,所以做一些基础的面试题练练手 public class Demo1 { public static void main(String[ ...
- UnityShader实例13:屏幕特效之均值模糊(Box Blur)
均值模糊(Box Blur) 概述 因为公司手游项目需求.须要一个适合手机平台的模糊效果,同一时候须要开放一个參数便于调节模糊值.我首先想到的就是ps里面的均值模糊. 查资料能够知道均值模糊是一种高速 ...
- Mosquito的优化——epoll优化(七)
本文由逍遥子撰写,转发请标注原址: http://blog.csdn.net/houjixin/article/details/46413583 或 http://houjixin.blog.163. ...
- UVALive 4225 / HDU 2964 Prime Bases 贪心
Prime Bases Problem Description Given any integer base b >= 2, it is well known that every positi ...
- 一个人的旅行 HDU杭电2066【dijkstra算法 || SPFA】
pid=2066">http://acm.hdu.edu.cn/showproblem.php? pid=2066 Problem Description 尽管草儿是个路痴(就是在杭电 ...
- PyCharm基本设置、常用快捷键
1. 下载安装 PyCharm官方下载地址: https://www.jetbrains.com/pycharm/download/index.html#section=windows 安装完成后在 ...