[BZOJ 1718] Redundant Paths
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=1718
[算法]
用Tarjan算法找出所有e-DCC(边-双联通分量),然后将这张图缩点,答案即为(缩点后的树的叶子节点的个数 + 1) / 2
[代码]
#include<bits/stdc++.h>
using namespace std;
#define MAXN 5010
#define MAXM 10010 struct edge
{
int to,nxt;
} e[MAXM << ]; int i,n,m,cnt,s,timer,tot;
int head[MAXN],u[MAXM],v[MAXM],low[MAXN],dfn[MAXN],belong[MAXN],degree[MAXN];
bool is_bridge[MAXM << ]; inline void addedge(int u,int v)
{
tot++;
e[tot] = (edge){v,head[u]};
head[u] = tot;
}
inline void tarjan(int u,int t)
{
int i,v;
dfn[u] = low[u] = ++timer;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (!dfn[v])
{
tarjan(v,i);
low[u] = min(low[u],low[v]);
if (low[v] > dfn[u])
is_bridge[i] = is_bridge[i ^ ] = true;
} else if (i != (t ^ )) low[u] = min(low[u],dfn[v]);
}
}
inline void dfs(int u)
{
int i,v;
belong[u] = cnt;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (!belong[v] && !is_bridge[i])
dfs(v);
}
} int main()
{ scanf("%d%d",&n,&m);
tot = ;
for (i = ; i <= m; i++)
{
scanf("%d%d",&u[i],&v[i]);
addedge(u[i],v[i]);
addedge(v[i],u[i]);
}
for (i = ; i <= n; i++)
{
if (!dfn[i])
tarjan(i,);
}
for (i = ; i <= n; i++)
{
if (!belong[i])
{
cnt++;
dfs(i);
}
}
for (i = ; i <= m; i++)
{
if (belong[u[i]] != belong[v[i]])
{
degree[belong[u[i]]]++;
degree[belong[v[i]]]++;
}
}
for (i = ; i <= cnt; i++) s += (degree[i] == );
printf("%d\n",(s + ) / ); return ; }
[BZOJ 1718] Redundant Paths的更多相关文章
- BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...
- 【bzoj1718】Redundant Paths 分离的路径
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 964 Solve ...
- [Usaco2006 Jan] Redundant Paths 分离的路径
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1132 Solv ...
- POJ 3177 Redundant Paths(边双连通的构造)
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13717 Accepted: 5824 ...
- [双连通分量] POJ 3177 Redundant Paths
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13712 Accepted: 5821 ...
- tarjan算法求桥双连通分量 POJ 3177 Redundant Paths
POJ 3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12598 Accept ...
- [POJ3177]Redundant Paths(双联通)
在看了春晚小彩旗的E技能(旋转)后就一直在lol……额抽点时间撸一题吧…… Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Tota ...
- poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11047 Accepted: 4725 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
随机推荐
- 【译】x86程序员手册02 - 基本的程序模式
Chapter 2 -- Basic Programming Model: 基本的程序模式 Introduces the models of memory organization. Defines ...
- Ubuntu14.4安装mysql
一.安装 apt-get install mysql-server mysql-client 设置用户名和密码 二.检查 sudo service mysql restart 三.支持 1.apach ...
- nuxt https
我用的模板是nxut-express,版本是:1.4.2.服务器:阿里云.一.申请免费证书:网站能通过https访问,首先得申请https证书,付费的阿里云上有售卖的,一年几千块.免费的可以通过cer ...
- getdlgitemtext
获取控件内信息 set 设置控件内信息 oninitdialog初始化控件时的操作
- CAD调用移动命令
主要用到函数说明: _DMxDrawX::SendStringToExecuteFun 把命令当着函数执行,可以传参数,详细说明如下: 参数 说明 IDispatch* pParam 命令参数,IMx ...
- CAD插入图块前修改图块文字
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- pandas - 案例(美国2012年总统候选人政治献金数据分析)
# 提供数据 months = {'JAN' : 1, 'FEB' : 2, 'MAR' : 3, 'APR' : 4, 'MAY' : 5, 'JUN' : 6, 'JUL' : 7, 'AUG' ...
- 【codeforces 755F】PolandBall and Gifts
[题目链接]:http://codeforces.com/contest/755/problem/F [题意] n个人; 计划是每个人都拿一个礼物来送给一个除了自己之外的人; 且如果一个人没有送出礼物 ...
- 联赛前集训日记Day3
考试 竟然出了道莫比乌斯函数的应用?? 简直没法玩 刷题 莫比乌斯函数摆在面前,咋能很快改完啊 生活 GGGGGGGGGGG 自己浪过头了,开回家一周 这车翻得猝不及防,然而自己作的,自己受,只是给别 ...
- springCloud学习-服务消费者(Feign)
1.简介 Feign是一个声明式的伪Http客户端,它使得写Http客户端变得更简单.使用Feign,只需要创建一个接口并注解.它具有可插拔的注解特性,可使用Feign 注解和JAX-RS注解.Fei ...