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 ...
随机推荐
- C#强制清除缓存
#region 强制清除缓存 [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize" ...
- 对List中对象的去重
今天项目中遇到了一个对List中对象去重的问题. 首先对于我们自己系统中的对象我们只要重写该对象的 equal 和 hashcode 即可(利用对象中的能够唯一确定对象的属性). 但是我遇到的不是本系 ...
- iOS - UITextField
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextField : UIControl <UITextInput, NSCoding> @ava ...
- [转发] 理解 oauth 2.0
原文: http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html oauth 的各种编程语言实现: http://oauth.net/2/ 理解OAu ...
- 纯css3样式属性制作各种图形图标
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- D3.js 交互式操作
与图表的交互,指在图形元素上设置一个或多个监听器,当事件发生时,做出相应的反应. 一.什么是交互 交互,指的是用户输入了某种指令,程序接受到指令之后必须做出某种响应.对可视化图表来说,交互能使图表更加 ...
- 主成分分析(PCA)原理及R语言实现
原理: 主成分分析 - stanford 主成分分析法 - 智库 主成分分析(Principal Component Analysis)原理 主成分分析及R语言案例 - 文库 主成分分析法的原理应用及 ...
- Linkclump – 批量打开多个链接[Chrome]
我的收藏 | 登录 首页 » Chrome » Linkclump – 批量打开多个链接[Chrome] 收藏 2 (1 votes) 青小蛙 on 2016.04.06. Linkclump 是一 ...
- String的那一大堆事儿--1
perfTimeStr = perfTimeStr.replace(perfTimeStr.substring(0,4), "____"); perfTimeStr = perfT ...
- jmeter 构建一个LDAP测试计划
添加用户 第一步你想做的每一个JMeter测试计划是添加一个线程组元素. 线程组告诉JMeter的用户数量你想模拟,用户应该发送的次数 请求,他们应该发送的请求的数量. 继续添加ThreadGroup ...