链接:

http://poj.org/problem?id=3177

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#problem/E

要去重边, 求再加上几条边任意两点直接都能到达

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std; #define N 100005 struct Edage
{
int v, next;
} e[N<<]; int n, Index, bnt, cnt, top;
int low[N], dfn[N], Head[N], Stack[N], belong[N], ru[N];
bool use[][]; void Init()
{
Index = bnt = top = ;
memset(low, , sizeof(low));
memset(dfn, , sizeof(dfn));
memset(Head, -, sizeof(Head));
memset(use, , sizeof(use));
memset(belong, , sizeof(belong));
memset(ru, , sizeof(ru));
}
void Add(int u, int v)
{
e[bnt].v = v;
e[bnt].next = Head[u];
Head[u] = bnt++;
}
void Tarjan(int u, int fa)
{
int v;
low[u] = dfn[u] = ++Index;
Stack[++top] = u; for(int j=Head[u]; j!=-; j=e[j].next)
{ v = e[j].v;
if(!dfn[v])
{
Tarjan(v, u);
low[u] = min(low[u], low[v]);
}
else if(v!=fa)
low[u] = min(low[u], dfn[v]);
} if(low[u]==dfn[u])
{
cnt++;
do
{
v = Stack[top--];
belong[v] = cnt;
}while(u!=v);
}
} int main()
{
int m;
while(scanf("%d%d", &n, &m)!=EOF)
{
int i, j, u, v; Init();
for(i=; i<m; i++)
{
scanf("%d%d", &u, &v); if(use[u][v]==false)
{
Add(u, v);
Add(v, u);
use[u][v] = use[v][u] = true;
} } Tarjan(, ); for(i=; i<=n; i++)
for(j=Head[i]; j!=-; j=e[j].next)
{
if(belong[i]!=belong[e[j].v])
ru[belong[i]]++;
} int ans=; for(i=; i<=cnt; i++)
{
if(ru[i]==)
ans++;
} printf("%d\n", (ans+)>>);
}
return ;
}

又看了一遍连通图, 把之前的题都看了一遍,虽然现在该学匹配了,我却还在这下功夫,但这是有点作用的,下次再复习一下估计理解就更好了

(连通图 ) Redundant Paths --POJ --3177的更多相关文章

  1. Redundant Paths POJ - 3177 把原图变成边—双连通图

    无向图概念:(这里的x->y表示x和y之间有一条无向边)1.桥:对于一个无向图,如果删除某条边后,该图的连通分量增加,则称这条边为桥 比如1->2->3->4这样一个简单得图一 ...

  2. E - Redundant Paths - poj 3177(缩点求叶子节点)

    题意:给一个图,想让每两个点之间都有两条路相连,不过特殊的是相同的两点之间多次相连被认为是一条边,现在求最少还需要添加几条边才能做到 分析:手欠没看清楚是相同的边只能相连一次,需要去重边,缩点后求出来 ...

  3. Redundant Paths POJ - 3177(边—双连通分量)

    题意: 在图中加边 看最少能通过加多少条边把 图变成边—双连通分量 解析: 先做一次dfs,不同的连通分量的low是不同的  注意重边 缩点 统计度为1的点  那么需要加的边为(ret+1)/2 #i ...

  4. POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)

    POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...

  5. POJ 3177 Redundant Paths POJ 3352 Road Construction

    这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...

  6. 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 ...

  7. POJ 3177——Redundant Paths——————【加边形成边双连通图】

    Redundant Paths Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  8. poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11047   Accepted: 4725 ...

  9. POJ 3177 Redundant Paths(边双连通的构造)

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13717   Accepted: 5824 ...

随机推荐

  1. How to Pronounce OPPORTUNITY

    How to Pronounce OPPORTUNITY Share Tweet Share Take the opportunity to learn this word!  Learn how t ...

  2. Golang 获取MD5的方法

    import ( "crypto/md5" "encoding/hex" ) //生成32位md5字串 func Md5(s string) string { ...

  3. Python的logging,记录log的包

    最近在做自动化测试时,想给他加上日志,所以用到logging的模块,以下是python增加log的几种方式 一.python代码配置方式(当然还有一种是可以多模块通用的一个python代码设置,这个网 ...

  4. Pie(浮点数二分)

    Pie http://poj.org/problem?id=3122 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2454 ...

  5. 整合Struts2框架和Spring框架

    -----------------------siwuxie095                                 整合 Struts2 框架和 Spring 框架         1 ...

  6. VMware虚拟机安装Centos预安装环境图文教程1

    前言: 习惯了微软的各种可视化开发软件环境,突然接触Linux命令式的操作环境,总是会让人有些反感跟抵触的. 经过了几天的研究,发现Linux也并不是那么的深不可测.在配置网站部署环境的时候,系统集成 ...

  7. [leetcode]146. LRU CacheLRU缓存

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...

  8. 搭建Eureka集群

    1.pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  9. springmvc 整合数据验证框架 jsr

    1.maven <dependency> <groupId>javax.validation</groupId> <artifactId>validat ...

  10. asp.net core 2.1 增加Nlog日志到sql server数据库

    一.增加引用 <PackageReference Include="NLog.Extensions.Logging" Version="1.2.1" /& ...