题目大意:给一张无向图,要求找一对$s$和$t$,使得其路径上的割边是最多的,输出其数量。

题解:把边双缩点以后求树的直径。

卡点:

C++ Code:

#include <cstdio>
#include <cstring>
#define maxn 300010
#define maxm 300010 #define ONLINE_JUDGE
#define read() R::READ()
#include <cctype>
namespace R {
int x;
#ifdef ONLINE_JUDGE
char *ch, op[1 << 26];
inline void init() {
fread(ch = op, 1, 1 << 26, stdin);
}
inline int READ() {
while (isspace(*ch)) ch++;
for (x = *ch & 15, ch++; isdigit(*ch); ch++) x = x * 10 + (*ch & 15);
return x;
}
#else
char ch;
inline int READ() {
ch = getchar();
while (isspace(ch)) ch = getchar();
for (x = ch & 15, ch = getchar(); isdigit(ch); ch = getchar()) x = x * 10 + (ch & 15);
return x;
}
#endif
} int n, m;
inline int min(int a, int b) {return a < b ? a : b;} namespace Tree {
int head[maxn], cnt;
struct Edge {
int to, nxt;
} e[maxm << 1];
void add(int a, int b) {
e[++cnt] = (Edge) {b, head[a]}; head[a] = cnt;
e[++cnt] = (Edge) {a, head[b]}; head[b] = cnt;
} int q[maxn], h = 1, t = 0;
int d[maxn];
int bfs(int rt) {
memset(d, 0, sizeof d);
d[q[h = t = 0] = rt] = 1;
while (h <= t) {
int u = q[h++];
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (!d[v]) {
d[v] = d[u] + 1;
q[++t] = v;
}
}
}
return q[t];
}
int work() {
int x = bfs(1), y = bfs(x);
return d[y] - 1;
}
}
namespace Graph {
int head[maxn], cnt;
struct Edge {
int from, to, nxt;
} e[maxm << 1];
void add(int a, int b) {
e[++cnt] = (Edge) {a, b, head[a]}; head[a] = cnt;
e[++cnt] = (Edge) {b, a, head[b]}; head[b] = cnt;
} int res[maxn], CNT;
int DFN[maxn], low[maxn], idx, fa[maxn];
int S[maxn], top;
void Tarjan(int u) {
DFN[u] = low[u] = ++idx;
S[++top] = u;
int v;
for (int i = head[u]; i; i = e[i].nxt) {
v = e[i].to;
if (v == fa[u]) continue;
if (!DFN[v]) {
fa[v] = u;
Tarjan(v);
low[u] = min(low[u], low[v]);
if (low[v] > DFN[u]) {
CNT++;
do res[v = S[top--]] = CNT; while (v != e[i].to);
}
} else low[u] = min(low[u], DFN[v]);
}
}
inline void tarjan(int n) {
for (int i = 1; i <= n; i++) if (!DFN[i]) Tarjan(i);
}
inline void init() {
for (int i = 1; i <= cnt; i += 2) {
if (res[e[i].from] != res[e[i].to]) Tree::add(res[e[i].from], res[e[i].to]);
}
}
} int main() {
#ifdef ONLINE_JUDGE
R::init();
#endif
n = read(), m = read();
for (int i = 1; i <= m; i++) Graph::add(read(), read());
Graph::tarjan(n);
Graph::init();
printf("%d\n", Tree::work());
return 0;
}

[CF1000E]We Need More Bosses的更多相关文章

  1. cf1000E We Need More Bosses (tarjan缩点+树的直径)

    题意:无向联通图,求一条最长的路径,路径长度定义为u到v必须经过的边的个数 如果把强联通分量都缩成一个点以后,每个点内部的边都是可替代的:而又因为这是个无向图,缩完点以后就是棵树,跑两遍dfs求直径即 ...

  2. 题解 CF1000E 【We Need More Bosses】

    这道题绝不是紫题... 题目的意思其实是让你求一个无向无重边图的直径. 对于求直径的问题我们以前研究过树的直径,可以两遍dfs或者两边bfs解决. 对于图显然不能这样解决,因为图上两点之间的简单路径不 ...

  3. CodeForces - 1000E :We Need More Bosses(无向图缩点+树的直径)

    Your friend is developing a computer game. He has already decided how the game world should look lik ...

  4. E - We Need More Bosses CodeForces - 1000E (tarjan缩点,树的直径)

    E - We Need More Bosses CodeForces - 1000E Your friend is developing a computer game. He has already ...

  5. We Need More Bosses CodeForces - 1000E(缩点 建图 求桥 求直径)

    题意: 就是求桥最多的一条路 解析: 先求连通分量的个数 然后缩点建图  求直径即可 #include <bits/stdc++.h> #define mem(a, b) memset(a ...

  6. 每日英语:Bosses May Use Social Media to Discriminate Against Job Seekers

    Many companies regularly look up job applicants online as part of the hiring process. A new study su ...

  7. CodeForces - 1000E We Need More Bosses

    题面在这里! 依然一眼题,求出割边之后把图缩成一棵树,然后直接求最长链就行了2333 #include<bits/stdc++.h> #define ll long long using ...

  8. Educational Codeforces Round 46 (Rated for Div. 2) E. We Need More Bosses

    Bryce1010模板 http://codeforces.com/contest/1000/problem/E 题意: 给一个无向图,求图的最长直径. 思路:对无向图缩点以后,求图的最长直径 #in ...

  9. We Need More Bosses CodeForces - 1000E (无向图缩点)

    大意: 给定无向连通图, 定义两个点$s,t$个价值为切断一条边可以使$s,t$不连通的边数. 求最大价值. 显然只有桥会产生贡献. 先对边双连通分量缩点建树, 然后求直径即为答案. #include ...

随机推荐

  1. LeetCode-177:第N高的薪水

    第N高的薪水与第二高的薪水,解题思路是一样的,只要对LeetCode-176的SQL做一下变形,便可以满足这题,详见:https://www.cnblogs.com/zouqf/p/10282392. ...

  2. 爬虫学习(十一)——bs4基础学习

    ba4的介绍: bs4是第三方提供的库,可以将网页生成一个对象,这个网页对象有一些函数和属性,可以快捷的获取网页中的内容和标签 lxml的介绍 lxml是一个文件的解释器,python自带的解释器是: ...

  3. js | JavaScript中数据类型转换总结

    转载 在js中,数据类型转换分为显式数据类型转换和隐式数据类型转换. 1, 显式数据类型转换 a:转数字: 1)Number转换: 代码: var a = “123”; a = Number(a); ...

  4. 【c学习-1】

    #include<stdio.h> int main(){ int a,b,max; printf("请输入两个整数:"); //格式化输出函数 scanf(" ...

  5. Redis ---------- Sort Set排序集合类型

    sortset是(list)和(set)的集中体现 与set的相同点: string类型元素的集合 不同点: sortset的元素:值+权 适合场合 获得最热门前5个帖子的信息 例如 select * ...

  6. yii rbac

    一.简介 什么是rbac ? rbac是就是基于角色的访问控制. yii提供一套基础的底层接口,我们知道,rbac经历好几个阶段,从rbac0到rbac3,从基础的用户.角色.权限,到动态的rbac处 ...

  7. (洛谷)P2709 小B的询问

    题目描述 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L..R]中的重 ...

  8. PCB工艺要求

    项目 加工能力 工艺详解   层数 1~6层 层数,是指PCB中的电气层数(敷铜层数).目前嘉立创只接受1~6层板.   板材类型 FR-4板材 板材类型:纸板.半玻纤.全玻纤(FR-4).铝基板,目 ...

  9. 3 网格 landing page

    0.大框架 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...

  10. javaScript对SEO的影响

    在两大搜索引擎阵营中,大量实践证明百度对JAVASCRIP的处理很不理想而GOOGLE的处理要好一些.   网页中出现大量的JavaScript会给搜索引擎爬行增加难度.其主要影响有以下几点: 1.干 ...