题目大意:给一张无向图,要求找一对$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. iOS第三方支付(支付宝)

    使用支付宝进行一个完整的支付功能,大致有以下步骤: 与支付宝签约,获得商户ID(partner)和账号ID(seller) 下载相应的公钥私钥文件(加密签名用) 下载支付宝SDK 生成订单信息 调用支 ...

  2. iOS之旅--隐藏(去除)导航栏底部横线

    iOS之旅--隐藏(去除)导航栏底部横线 iOS开发大部分情况下会使用到导航栏,由于我司的app导航栏需要与下面紧挨着的窗口颜色一致,导航栏底部的横线就会影响这个美观,LZ使用了以下方法.觉得不错,分 ...

  3. C/C++获取本机名+本机IP+本机MAC

    本机名.IP.MAC都是一些比较常用网络参数,怎么用C/C++获取呢? 研究了两三个小时... 需要说明的都在代码注释里 #include <stdio.h> #include <W ...

  4. mysql 1055 的错误

    1.Err1055,出现这个问题往往是在执行sql语句时候,在最后一行会出现这个问题. [Err] 1055 - Expression #1 of ORDER BY clause is not in ...

  5. 创建数据库配置文件ini(转)

    一.有必要了解INI文件的结构: ;注释 [小节名] 关键字=值 ... ---- INI文件允许有多个小节,每个小节又允许有多个关键字, “=”后面是该关键字的值. ---- 值的类型有三种:字符串 ...

  6. 1016-02-首页17-添加转发微博控件-计算转发配图的 Frame-------打印出 被转发微博的模型

    说明:HWStatus为微博模型,_retweeted_status 为返回的数据( 一条微博模型)里面的一个属性,_retweeted_status 不为空表示此微博是否转发了其他微博._retwe ...

  7. C语言函数篇(二)函数参数基础设计

    形参实现一种数据传入的接口 ,由 实参 拷贝给 形参. 拷贝!!!!!!!!!!! 例1: void func(int tmp){ //意图是实现传进来的参数 +1 tmp++; } int mian ...

  8. js石头剪刀布小游戏

    代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...

  9. 15.5,centos下redis安全相关

      博文背景: 由于发现众多同学,在使用云服务器时,安装的redis3.0+版本都关闭了protected-mode,因而都遭遇了挖矿病毒的攻击,使得服务器99%的占用率!! 因此我们在使用redis ...

  10. poj2001Shortest Prefixes(trie)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18687   Accepted: 808 ...