BZOJ1718 [Usaco2006 Jan] Redundant Paths 分离的路径
给你一个无向图,问至少加几条边可以使整个图变成一个双联通分量
简单图论练习= =
先缩点,ans = (度数为1的点的个数) / 2
这不是很好想的么QAQ
然后注意位运算的优先级啊魂淡!!!你个sb调了一个下午!!!
/**************************************************************
Problem: 1718
User: rausen
Language: C++
Result: Accepted
Time:44 ms
Memory:3148 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int N = 5e4 + ;
const int M = 1e5 + ; struct edge {
int next, to;
edge(int _n = , int _t = ) : next(_n), to(_t) {}
} e[M]; int n, m, ans;
int cnt, top, num, tot = ;
int dfn[N], low[N], vis[N], sz[N], s[N], w[N], first[N];
int mp[N]; inline void Add_Edges(int x, int y) {
e[++tot] = edge(first[x], y), first[x] = tot;
e[++tot] = edge(first[y], x), first[y] = tot;
} void DFS(int p, int from) {
dfn[p] = low[p] = ++cnt;
s[++top] = p, vis[p] = ;
#define y e[x].to
register int x;
for (x = first[p]; x; x = e[x].next)
if (x != (from ^ )) {
if (!vis[y]) DFS(y, x);
if (vis[y] < ) low[p] = min(low[p], low[y]);
}
#undef y
if (dfn[p] == low[p]) {
register int y;
++num;
while (s[top + ] != p) {
y = s[top--];
vis[y] = , w[y] = num;
++sz[num];
}
}
} inline void tarjan() {
int i;
cnt = top = num = ;
memset(vis, sizeof(vis), );
for (i = ; i <= n; ++i)
if (!vis[i]) DFS(i, );
} int main() {
int i, x, y;
scanf("%d%d", &n, &m);
for (i = ; i <= m; ++i) {
scanf("%d%d", &x, &y);
Add_Edges(x, y);
}
tarjan();
#define y e[x].to
memset(mp, , sizeof(mp));
for (i = ; i <= n; ++i)
for (x = first[i]; x; x = e[x].next)
if (w[i] != w[y]) ++mp[w[y]];
for (ans = i = ; i <= num; ++i)
ans += (mp[i] == );
printf("%d\n", ans >> );
#undef y
return ;
BZOJ1718 [Usaco2006 Jan] Redundant Paths 分离的路径的更多相关文章
- [BZOJ1718]:[Usaco2006 Jan] Redundant Paths 分离的路径(塔尖)
题目传送门 题目描述 为了从F个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了被迫走某一条路,所以她们想建一些新路,使每一对草场之间都会至少有两条相互分 ...
- BZOJ1718: [Usaco2006 Jan] Redundant Paths 分离的路径【边双模板】【傻逼题】
LINK 经典傻逼套路 就是把所有边双缩点之后叶子节点的个数 //Author: dream_maker #include<bits/stdc++.h> using namespace s ...
- BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...
- [Usaco2006 Jan] Redundant Paths 分离的路径
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1132 Solv ...
- BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径
Description 给出一个无向图,求将他构造成双连通图所需加的最少边数. Sol Tarjan求割边+缩点. 求出割边,然后缩点. 将双连通分量缩成一个点,然后重建图,建出来的就是一棵树,因为每 ...
- 【BZOJ】1718: [Usaco2006 Jan] Redundant Paths 分离的路径
[题意]给定无向连通图,要求添加最少的边使全图变成边双连通分量. [算法]Tarjan缩点 [题解]首先边双缩点,得到一棵树(无向无环图). 入度为1的点就是叶子,两个LCA为根的叶子间合并最高效,直 ...
- bzoj 1718: [Usaco2006 Jan] Redundant Paths 分离的路径【tarjan】
首先来分析一下,这是一张无向图,要求没有两条路联通的点对个数 有两条路连通,无向图,也就是说,问题转化为不在一个点双连通分量里的点对个数 tarjan即可,和求scc还不太一样-- #include& ...
- 【bzoj1718】Redundant Paths 分离的路径
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 964 Solve ...
- Redundant Paths 分离的路径【边双连通分量】
Redundant Paths 分离的路径 题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields ...
随机推荐
- HDU-4518 吉哥系列故事——最终数 AC自动机+数位DP
题意:如果一个数中的某一段是长度大于2的菲波那契数,那么这个数就被定义为F数,前几个F数是13,21,34,55......将这些数字进行编号,a1 = 13, a2 = 21.现给定一个数n,输出和 ...
- c point ccccc
代码来自<K&R> 范例输入(控制台): -32 23 11 1833987 23^Z 范例输出: -322311183398723 #include<stdio.h> ...
- poj2074Line of Sight(直线相交)
链接 几何细节题. 对于每一个障碍物可以求出它在地产线上的覆盖区间,如下图. 紫色部分即为每个障碍物所覆盖掉的区间,求出所有的,扫描一遍即可. 几个需要注意的地方:直线可能与地产线没有交点,可视区间可 ...
- poj1474Video Surveillance(半平面交)
链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...
- hdu 1573 X问题
数论题,本想用中国剩余定理,可是取模的数之间不一定互质,用不了,看到网上有篇文章写得很好的:数论——中国剩余定理(互质与非互质),主要是采用合并方程的思想: 大致理解并参考他的代码后便去试试hdu上这 ...
- 使用==比较String类型
String类型的比较 public class StringDemo { public static void main(String[] args) { String s1 = "abc ...
- What is the difference between extensibility and scalability?
You open a small fast food center, with a serving capacity of 5-10 people at a time. But you have en ...
- php中的 == 和 ===
== 是等值 1 和 ‘1’ 是相等的 === 要等值并且类型相等,比如 1 和 ‘1’ 是不相等的,只有 ‘1’ 和 ‘1’ 是相等的.哈哈哈. http://ihacklog.com/post ...
- Linux下scp命令的用法
scp 对拷文件夹 和 文件夹下的所有文件 对拷文件并重命名 对拷文件夹 (包括文件夹本身) scp -r /home/wwwroot/www/charts/util root@192.168.1 ...
- 解决 placeholder 垂直不居中,偏上的问题
解决 placeholder 垂直不居中,偏上的问题 安卓浏览器显示placeholder 垂直不居中,而iphone没问题,搜了一下答案,解决方法是把input的line-height去掉就行 参考 ...