poj 3352 Road Construction(边双连通分量+缩点)
题目链接:http://poj.org/problem?id=3352
这题和poj 3177 一样,参考http://www.cnblogs.com/frog112111/p/3367039.html
AC代码:
#include<cstdio>
#include<cstring>
const int N=+;
const int M=+; struct EDGE
{
int v,next;
}edge[M*];
int first[N],low[N],dfn[N],belong[N],degree[N],sta[M],instack[M];
int g,cnt,top,scc;
int min(int a,int b)
{
return a<b?a:b;
}
void AddEdge(int u,int v)
{
edge[g].v=v;
edge[g].next=first[u];
first[u]=g++;
}
void Tarjan(int u,int fa)
{
int i,v;
low[u]=dfn[u]=++cnt;
sta[++top]=u;
instack[u]=;
for(i=first[u];i!=-;i=edge[i].next)
{
v=edge[i].v;
if(i==(fa^))
continue;
if(!dfn[v])
{
Tarjan(v,i);
low[u]=min(low[u],low[v]);
}
else if(instack[v])
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
scc++;
while()
{
v=sta[top--];
instack[v]=;
belong[v]=scc;
if(v==u)
break;
}
}
}
int main()
{
int n,m,u,v,i,j;
scanf("%d%d",&n,&m);
g=cnt=top=scc=;
memset(first,-,sizeof(first));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(instack,,sizeof(instack));
memset(degree,,sizeof(degree));
for(i=;i<m;i++)
{
scanf("%d%d",&u,&v);
{
AddEdge(u,v);
AddEdge(v,u);
}
}
for(i=;i<=n;i++)
if(!dfn[i])
Tarjan(,-);
for(i=;i<=n;i++)
{
for(j=first[i];j!=-;j=edge[j].next)
{
v=edge[j].v;
if(belong[i]!=belong[v])
degree[belong[i]]++;
}
}
int sum=;
for(i=;i<=n;i++)
if(degree[i]==)
sum++;
int ans=(sum+)/;
printf("%d\n",ans);
return ;
}
poj 3352 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 3352 Road Construction(边双连通分量,桥,tarjan)
题解转自http://blog.csdn.net/lyy289065406/article/details/6762370 文中部分思路或定义模糊,重写的红色部分为修改过的. 大致题意: 某个企业 ...
- POJ 3352 Road Construction (边双连通分量)
题目链接 题意 :有一个景点要修路,但是有些景点只有一条路可达,若是修路的话则有些景点就到不了,所以要临时搭一些路,以保证无论哪条路在修都能让游客到达任何一个景点 思路 :把景点看成点,路看成边,看要 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- POJ 3352 Road Construction(边—双连通分量)
http://poj.org/problem?id=3352 题意: 给出一个图,求最少要加多少条边,能把该图变成边—双连通. 思路:双连通分量是没有桥的,dfs一遍,计算出每个结点的low值,如果相 ...
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
- POJ 3352 Road Construction 双联通分量 难度:1
http://poj.org/problem?id=3352 有重边的话重边就不被包含在双连通里了 割点不一定连着割边,因为这个图不一定是点连通,所以可能出现反而多增加了双连通分量数的可能 必须要用割 ...
- poj 3177 Redundant Paths(边双连通分量+缩点)
链接:http://poj.org/problem?id=3177 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使得任 ...
随机推荐
- 图、dfs、bfs
graphdfsbfs 1.clone graph2.copy list with random pointer3.topological sorting4.permutations5.subsets ...
- ESP32 ADC
2个12位的ADC,共计18通道,ADC2比较特殊的一点就是:ADC2和wifi共用,wifi的优先级更高,所以ADC2只有在WIFI模块不用的情况下好使: 在读取ADC数据之前,必须先对ADC进行设 ...
- Android Canvas saveLayerAlpha使用
Canvas.saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int saveFlags): 本 ...
- x509: certificate signed by unknown authority harbor 架构图
默认时,client 与 Registry 的交互是通过 https 通信的.在 install Registry 时,若未配置任何tls 相关的 key 和 crt 文件,https 访问必然失败. ...
- 4.3《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)—链接到目录
在4.2章中我们已经会用cd进入到指定的目录中.这是导航最常见的用途之一,但是它还有几个值得关注的用途.第一个是使用cd ..(读作'see-dee 点点')返回当前目录级别的上一级: $ pwd / ...
- c#对联合体的封装
https://blog.csdn.net/u012846041/article/details/37518313 标准C或者C++中均提供关键字定义联合结构,C#中未提供类似的关键字,但仍然可以定义 ...
- decorator, async/await, generator
////////////decorator////////// function aopFunc (target, key, descriptor) { console.log('aopFunc') ...
- Ionic App 启动时报Application Error - The connection to the server was unsuccessful
最近在更新App的时候,发现在华为手机上报这个错误,有点困惑,查找资料分析,大概原因是程序在加载index.html网页时,加载的资源过多,造成时间超时, 这个时原因分析https://stackov ...
- [Spark][Python]对HDFS 上的文件,采用绝对路径,来读取获得 RDD
对HDFS 上的文件,采用绝对路径,来读取获得 RDD: In [102]: mydata=sc.textFile("file:/home/training/test.txt")1 ...
- TensorFlow框架下的RNN实践小结
截至目前,TensorFlow的RNN APIs还处于Draft阶段.不过据官方解释,RNN的相关API已经出现在Tutorials里了,大幅度的改动应该是不大可能,现在入手TF的RNN APIs风险 ...