poj 3352 边连通分量
思路与poj3177一模一样。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define Maxn 1010
#define Maxm Maxn*Maxn
#define inf 0x7fffffff
using namespace std;
int dfn[Maxn],low[Maxn],degree[Maxn],e,n,lab,index[Maxn];
struct Edge{
int to,from,next,v;
}edge[Maxm];
void init()
{
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(degree,,sizeof(degree));
memset(index,-,sizeof(index));
e=lab=;
}
void addedge(int from, int to)
{
edge[e].v=;
edge[e].from=from;
edge[e].to=to;
edge[e].next=index[from];
index[from]=e++;
edge[e].v=;
edge[e].from=to;
edge[e].to=from;
edge[e].next=index[to];
index[to]=e++;
}
void dfs(int u)
{
dfn[u]=low[u]=++lab;
int i,j,temp;
for(i=index[u];i!=-;i=edge[i].next)
{
temp=edge[i].to;
if(edge[i].v) continue;
edge[i].v=edge[i^].v=;
if(!dfn[temp])
{
dfs(temp);
low[u]=min(low[u],low[temp]);
}
low[u]=min(low[u],dfn[temp]);
}
}
int solve()
{
int i,j,temp=;
for(i=;i<=n;i++)
{
for(j=index[i];j!=-;j=edge[j].next)
{
if(low[i]!=low[edge[j].to])
degree[low[i]]++;
}
}
for(i=;i<=n;i++)
if(degree[i]==)
temp++;
return (temp+)/;
}
int main()
{
int m,i,j,a,b;
while(scanf("%d%d",&n,&m)!=EOF)
{
init();
for(i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
addedge(a,b);
}
dfs();
printf("%d\n",solve()); }
return ;
}
poj 3352 边连通分量的更多相关文章
- poj 3352 双连通分量
至少加几条边成为双连通分量 #include <iostream> #include <cstdio> #include <cstring> using names ...
- POJ 3352 (边双连通分量)
题目链接: http://poj.org/problem?id=3352 题目大意:一个连通图中,至少添加多少条边,使得删除任意一条边之后,图还是连通的. 解题思路: 首先来看下边双连通分量的定义: ...
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- POJ 3352 Road Construction(边—双连通分量)
http://poj.org/problem?id=3352 题意: 给出一个图,求最少要加多少条边,能把该图变成边—双连通. 思路:双连通分量是没有桥的,dfs一遍,计算出每个结点的low值,如果相 ...
- poj 3352 Road Construction(边双连通分量+缩点)
题目链接:http://poj.org/problem?id=3352 这题和poj 3177 一样,参考http://www.cnblogs.com/frog112111/p/3367039.htm ...
- 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 (边双连通分量)
题目链接 题意 :有一个景点要修路,但是有些景点只有一条路可达,若是修路的话则有些景点就到不了,所以要临时搭一些路,以保证无论哪条路在修都能让游客到达任何一个景点 思路 :把景点看成点,路看成边,看要 ...
随机推荐
- thymeleaf中的Literals
Literals即为文字 一.Text literals:文本文字 文本文字只是字符串指定的单引号之间.他们可以包含任何字符,但你应避免任何单引号里面\ ' <p> Now you are ...
- codeforces 617BChocolate
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- [iOS 多线程 & 网络 - 1.0] - 多线程概述
A.进程 什么是进程进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内 比如同时打开QQ.Xcode,系统就会分别启动2个进程 通过"活 ...
- EasyUI datagrid添加右键菜单项
js代码 //动态加载数据表格 function InitData() { $('#grid').datagrid({ url: '/Home/Query?r=' + Math.random(), / ...
- EasyUI 下拉列表联动
//绑定部门.人员下拉菜单项 function BindDdl() { var $ddlbm = $("#ddlBm");//部门下拉列表 var $ddlry = $(" ...
- 用BenchmarkDotNet给C#程序做性能测试
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:用BenchmarkDotNet给C#程序做性能测试.
- 神经网络学习-问题(二)-scipy未正确安装报DLL找不到的问题
问题如下: E:\project\DL\python\keras>python keras_sample.pyUsing Theano backend.Traceback (most recen ...
- SSH登录失败:Host key verification failed
转载自:https://help.aliyun.com/knowledge_detail/41471.html 注意:本文相关 Linux 配置及说明已在 CentOS 6.5 64 位操作系统中进行 ...
- C#小常识集锦(一)--《更锋利的CSharp代码》读书笔记
❀.采用类似匈牙利命名法为控件命令,对于其他变量申明则不需要了 e.g. Button btnAdd; e.g. TextBox txtUsername; e.g. ListBox lstFileNa ...
- 通过程序 VB.Net 或 C# 读取文本文件行数
1, VB.NET 读取 (通过streamReader) ' tmpCount = 0 'Dim tmpSR As New StreamReader(fileFullName, System.Tex ...