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值,如果相 ...
随机推荐
- 模板 FFT 快速傅里叶变换
FFT模板,原理不难,优质讲解很多,但证明很难看太不懂 这模板题在bzoj竟然是土豪题,服了 #include <cmath> #include <cstdio> #inclu ...
- com.jasson.im.api.APIClient jar包 下载
包名:ImApi2.3.jar 链接: https://pan.baidu.com/s/1SgeufcaH6y_K-AJEKDZDtw 提取码: 3v78 复制这段内容后打开百度网盘手机App,操作更 ...
- 好文应该收藏-----redis 配置自启动
话不多说,请看原作者笔记,亲测,可用 https://blog.csdn.net/qq_42810276/article/details/81296012
- JavaScript 常见创建对象的方式
JavaScript 有哪几种创建对象的方式? javascript创建对象简单的说,无非就是使用内置对象或各种自定义对象,当然还可以用JSON:但写法有很多种,也能混合使用. (1)对象字面量的方式 ...
- Maven学习总结(25)——Eclipse Maven Update 时JDK版本变更问题
1.新建一个Maven项目JDK版本和系统版本不对应, 2.右键Maven项目->Maven->Update ProjectJDK版本改变了, 3.操作系统的JDK重装了新的版本,这是引起 ...
- ASP.NET-入门
MVC5特点 1.One ASP.NET统一平台 2.Bootstrap 免费CSS,响应式页面 3.路由标记属性:简单.控制器.操作.前缀.参数.URL 4.ASP.NET web API 2 : ...
- jQuery中focusin()和focus()、find()和children()的差别
jQuery中focus()和focusin().focus()和children()的差别 focus()和focusin() focus()和focusin()的差别在于focusin()支持事件 ...
- 微软柯塔娜(Cortana)的一句名言
近日.媒体频传Win 10装机量已经超过多少千万台.我操心的问题是,集成在Win 10操作系统中的柯塔娜小姐将怎样面对各色各样的人群.由于,在这个世界上.人是最复杂的生物,什么人都有. 依据国外媒体报 ...
- [JZOJ 5465] [NOIP2017提高A组冲刺11.9] 道路重建 解题报告 (e-dcc+树的直径)
题目链接: http://172.16.0.132/senior/#main/show/5465 题目: 小X所居住的X国共有n个城市,有m条无向道路将其连接.作为一个统一的国家,X 城的任意两个城市 ...
- 洛谷P2118 比例简化(暴力)
题目描述 在社交媒体上,经常会看到针对某一个观点同意与否的民意调查以及结果.例如,对某一观点表示支持的有1498 人,反对的有 902人,那么赞同与反对的比例可以简单的记为1498:902. 不过,如 ...