题面在这里!

依然一眼题,求出割边之后把图缩成一棵树,然后直接求最长链就行了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. 【BZOJ】3790 神奇项链

    [算法](manacher+贪心)||(manacher+DP+树状数组/线段树) [题解] manacher求回文串,后得到线段,做一点计算映射回原串线段. 然后问题转化为可重叠区间线段覆盖问题,可 ...

  2. 关于反序列化时抛出java.io.EOFException异常

    https://www.cnblogs.com/ouhaitao/p/7683568.html https://blog.csdn.net/mym43210/article/details/40081 ...

  3. 一键前端代理,一行命令开启nginx容器,代理前端页面

    我们在前端开发的过程中,在对接口时候,往往需要跨域请求,那么及其简便的方法就是使用nginx反向代理,但是存在几点缺点 1.在新的一个项目下,我们需要找到安装nginx目录的nginx.conf文件并 ...

  4. vue实现微信对话

    因为项目中需要实现仿微信对话功能,于是抽空实现了下,主要是h5的canvas的把图片和文字绘制到画布上 原文来自我的个人博客:http://lvhww.com/index.php/archives/6 ...

  5. Eclipse连接海马模拟器

    找到海马模拟器安装目录: 使用cmd 命令进入命令行:D: cd:D:\Program Files (x86)\Droid4X 进入模拟器所在目录 运行adb connect 127.0.0.1:26 ...

  6. js中的true和false

    1.false undefined.NaN.0.null和空字符串''均被视为false 2.true 除上述以外的其它情况一律被视作true

  7. javaWeb面试题(重要)

    1.Javaweb 技术的结构  1.1 技术结构图

  8. 通过JDBC连接HiveServer2

    如果通过JDBC连接HiveServer2时提示:User: hive is not allowed to impersonate hive,需要在core-site.xml中新增如下配置: hado ...

  9. Python自动化运维 - Django(三)CSRF - Cookie&Session

    CSRF跨站请求伪造 CSRF跨站点请求伪造(Cross—Site Request Forgery),跟XSS攻击一样,存在巨大的危害性,你可以这样来理解:攻击者盗用了你的身份,以你的名义发送恶意请求 ...

  10. Linux内核通知链分析【转】

    转自:http://www.cnblogs.com/jason-lu/articles/2807758.html Linux内核通知链分析 1. 引言 Linux是单内核架构(monolithic k ...