大意: 给定无向连通图, 定义两个点$s,t$个价值为切断一条边可以使$s,t$不连通的边数. 求最大价值.

显然只有桥会产生贡献. 先对边双连通分量缩点建树, 然后求直径即为答案.

#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back
using namespace std; const int N = 3e5+10;
int n,m,clk,ans,cnt;
int dfn[N],low[N],dep[N],q[N],bcc[N];
vector<int> g[N],gg[N]; void dfs(int x, int fa) {
dfn[x]=low[x]=++clk;
q[++*q] = x;
for (int y:g[x]) if (y!=fa) {
if (dfn[y]) low[x]=min(low[x],dfn[y]);
else {
dfs(y,x);
low[x] = min(low[x],low[y]);
}
}
if (low[x]==dfn[x]) {
++cnt;
do bcc[q[*q]] = cnt; while (q[(*q)--]!=x);
}
}
void dfs2(int x, int fa) {
for (int y:gg[x]) if (y!=fa) {
dfs2(y,x);
ans = max(ans, dep[x]+dep[y]+1);
dep[x] = max(dep[x],dep[y]+1);
}
}
int main() {
scanf("%d%d", &n, &m);
while (m--) {
int u, v;
scanf("%d%d", &u, &v);
g[u].pb(v),g[v].pb(u);
}
dfs(1,0);
REP(i,1,n) for (int j:g[i]) {
if (bcc[i]!=bcc[j]) {
gg[bcc[i]].pb(bcc[j]);
}
}
dfs2(1,0);
printf("%d\n", ans);
}

We Need More Bosses CodeForces - 1000E (无向图缩点)的更多相关文章

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

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

  2. 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 ...

  3. Cactus CodeForces - 231E (无向图缩环)

    大意: 给定无向图, 每个点最多属于一个简单环, 多组询问, 求给定起点终点, 有多少条简单路径. 先缩环, 然后假设两点树上路径经过$cnt$个环, 那么答案就为$2^{cnt}$. 要注意缩环建树 ...

  4. hdu-4612(无向图缩点+树的直径)

    题意:给你n个点和m条边的无向图,问你如果多加一条边的话,那么这个图最少的桥是什么 解题思路:无向图缩点和树的直径,用并查集缩点: #include<iostream> #include& ...

  5. HDOJ 5409 CRB and Graph 无向图缩块

    无向图缩块后,以n所在的块为根节点,dp找每块中的最大值. 对于每一个桥的答案为两块中的较小的最大值和较小的最大值加1 CRB and Graph Time Limit: 8000/4000 MS ( ...

  6. POJ 3177 (Redundant Paths) —— (有重边,边双联通,无向图缩点)

    做到这里以后,总算是觉得tarjan算法已经有点入门了. 这题的题意是,给出若干个点和若干条边连接他们,在这个无向图中,问至少增加多少条边可以使得这个图变成边双联通图(即任意两点间都有至少两条没有重复 ...

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

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

  8. Codeforces Round #143 (Div. 2) E. Cactus 无向图缩环+LCA

    E. Cactus   A connected undirected graph is called a vertex cactus, if each vertex of this graph bel ...

  9. Codeforces 1000E We Need More Bosses (边双连通+最长链)

    <题目链接> 题目大意:给定一个$n$个节点$m$条边的无向图,问你对任意两点,最多有多少条特殊边,特殊边指删除这条边后,这两个点不能够到达. 解题分析: 特殊变其实就是指割边,题意就是问 ...

随机推荐

  1. firewall-cmd命令详解

    https://blog.csdn.net/GMingZhou/article/details/78090963 实例 # 安装firewalld yum install firewalld fire ...

  2. Thingsboard学习之一CentOS安装系统更新

    首先安装好系统,查询到系统的IP地址后,使用Putty登入系统 更新系统 yum update 安装git yum install git 动图演示

  3. Cookie 概述

    一.属性介绍 Name Cookie的key Value Cookie的value Domain 可以访问此Cookie的域名 Path 可以访问此Cookie的页面路径 Expires/Max-Ag ...

  4. ab 压测

    Linux学习14-ab报错apr_pollset_poll: The timeout specified has expired (70007) 前言 使用ab压力测试时候出现报错apr_polls ...

  5. madam、Linux LVM的使用

    .RaidRAID(独立冗余磁盘阵列)概念:RAID技术通过把多个硬盘设备组合成一个容量更大.安全性更好的磁盘阵列,并把数据切割成多个区段后分别存放在各个不同的物理硬盘设备上,然后利用分散读写技术来提 ...

  6. mac安装 bcolz出现错误

    使用的是命令pip install bcolz c-blosc//snappy-stubs-:: fatal error: 'algorithm' file not found #include &l ...

  7. Function mysql_db_query() is deprecated 错误解决

    方法一:@ 在任何错误语句之前加上@符号,即可屏蔽! 方法二:error_reporting 在PHP文件第一行加上:error_reporting(0); 即可屏蔽! 方法三:display_err ...

  8. webpack——Modules && Hot Module Replacement

    blog:JavaScript Module Systems Showdown: CommonJS vs AMD vs ES2015 官网链接: Modules 官网链接:Hot Module Rep ...

  9. MySQL之二进制日志

    一.Binlog日志格式 根据日志定义的格式不一样,可以分为Statement格式.Row格式或者MIXED格式 mysql5.6----> | binlog_format | STATEMEN ...

  10. 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_10-SpringSecurityOauth2研究-校验令牌&刷新令牌

    3.5校验令牌 Spring Security Oauth2提供校验令牌的端点,如下: Get: http://localhost:40400/auth/oauth/check_token?token ...