题面在这里!

依然一眼题,求出割边之后把图缩成一棵树,然后直接求最长链就行了2333

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define pb push_back
const int N=300005; vector<int> g[N];
int dfn[N],low[N],num=1,hd[N],n,m,ans=0,v[N];
int to[N*2],ne[N*2],cnt,col[N],mx[N],dc;
bool ban[N*2]; inline void add(int x,int y){ to[++num]=y,ne[num]=hd[x],hd[x]=num;} void tarjan(int x,int fa){
dfn[x]=low[x]=++dc; for(int i=hd[x];i;i=ne[i]) if(to[i]!=fa)
if(!dfn[to[i]]){
tarjan(to[i],x);
low[x]=min(low[x],low[to[i]]);
if(low[to[i]]>dfn[x]) ban[i]=ban[i^1]=1;
}
else low[x]=min(low[x],dfn[to[i]]);
} void B(int x){
col[x]=cnt; for(int i=hd[x];i;i=ne[i])
if(ban[i]){
if(col[to[i]]&&v[to[i]]!=cnt){
v[to[i]]=cnt;
g[cnt].pb(col[to[i]]);
g[col[to[i]]].pb(cnt);
}
}
else if(!col[to[i]]) B(to[i]);
} void dfs(int x,int fa){
for(int i:g[x]) if(i!=fa){
dfs(i,x),ans=max(ans,mx[i]+1+mx[x]);
mx[x]=max(mx[x],mx[i]+1);
}
} int main(){
scanf("%d%d",&n,&m);
int uu,vv;
for(int i=1;i<=m;i++){
scanf("%d%d",&uu,&vv);
add(uu,vv),add(vv,uu);
} tarjan(1,0); for(int i=1;i<=n;i++) if(!col[i]){
cnt++,B(i);
} dfs(1,0); printf("%d\n",ans);
return 0;
}

CodeForces - 1000E We Need More Bosses的更多相关文章

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

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

  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. 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. We Need More Bosses CodeForces - 1000E(缩点 建图 求桥 求直径)

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

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

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

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

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

  7. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  8. Educational Codeforces Round 46 (Div 2) (A~G)

    目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...

  9. 【50.88%】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. Calendar Provider

    英文原文:http://developer.android.com/guide/topics/providers/calendar-provider.html 关键类 CalendarContract ...

  2. Unity下的ECS框架 Entitas简介

    最近随着守望先锋制作组在gdc上发布的一个关于ecs的talk,ecs这个架构算是得到了一定的曝光度. 在这之前,github上就一直有一个C#的ecs框架名为Entitas,截止现在已经有1300+ ...

  3. 铺砖问题 (状态压缩dp)

    问题描述: 给定m×n个格子,每个格子被染成了黑色或白色.现在要用1×2的砖块覆盖这些格子,要求快于快之间互相不重叠,且覆盖了所有白色的格子(用 . 表示),但不覆盖任意一个黑色的格子(用 x 表示) ...

  4. 前端—css

    css css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离. 一.css的四种引入方式: 1.行内式   ...

  5. C++学习之路(三):volatile关键字

    volatile是c++中的一个关键字.用volatile修饰的变量,具有三个性质:易变性 (一)易变性: 由于编译器对代码执行的优化,两条赋值语句,下一条语句可能会直接从上一条语句使用的寄存器中取得 ...

  6. Linux内核模块编程可以使用的内核组件

    2.2.2 在阅读<深入Linux内核架构与底层原理> 作者:刘京洋 韩方,发现一些错误,有些自己的理解,特以此记录 1.工作队列(workqueue) 队列是一种可以先进先出的数据结构, ...

  7. 64_g6

    gsettings-desktop-schemas-devel-3.24.0-1.fc26.x..> 22-Mar-2017 20:46 19386 gsf-sharp-0.8.1-27.fc2 ...

  8. 菜鸟学习nodejs--Socket.IO即时通讯

    https://blog.csdn.net/lovemenghaibin/article/details/51263774

  9. MVC 从控制器将数据对象赋值给前端JS对象

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

  10. 2017多校第5场 HDU 6085 Rikka with Candies bitset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6085 题意:存在两个长度为n,m的数组A,B.有q个询问,每个询问有一个数字k,可以得到Ai%Bj=k ...