题意理解了就很好做

题意:给一张无向图,任意取两个点s,t,s->t的路径上必经边数量为k

求这样的s,t,使得k最大

#include<bits/stdc++.h>
#define maxn 300005
using namespace std;
struct Edge{int to,nxt,b;}e[maxn<<],e_c[maxn<<];
int head[maxn],tot,head_c[maxn],tot_c,n,m;
void init(){
memset(head,-,sizeof head);
memset(head_c,-,sizeof head_c);
tot=tot_c=;
}
void add(int u,int v){
e[tot].to=v;e[tot].nxt=head[u];head[u]=tot++;
}
void add_c(int u,int v){
e_c[tot_c].to=v;e_c[tot_c].nxt=head_c[u];head_c[u]=tot_c++;
} int ind,low[maxn],dfn[maxn];
void tarjan(int x,int in_edge){
low[x]=dfn[x]=++ind;
for(int i=head[x];i!=-;i=e[i].nxt){
int y=e[i].to;
if(!dfn[y]){
tarjan(y,i);
low[x]=min(low[x],low[y]);
if(low[y]>dfn[x])
e[i].b=e[i^].b=;
}
else if(i!=(in_edge^))
low[x]=min(low[x],dfn[y]);
}
}
int c[maxn],dcc;
void dfs1(int x){
c[x]=dcc;
for(int i=head[x];i!=-;i=e[i].nxt){
int y=e[i].to;
if(e[i].b || c[y]!=)continue;
dfs1(y);
}
} int dp[maxn],ans;
void dfs2(int x,int pre){
for(int i=head_c[x];i!=-;i=e_c[i].nxt){
int y=e_c[i].to;
if(y==pre)continue;
dfs2(y,x);
ans=max(ans,dp[x]+dp[y]+);
dp[x]=max(dp[x],dp[y]+);
}
} int main(){
init();
cin>>n>>m;int u,v;
for(int i=;i<=m;i++){
cin>>u>>v;
add(u,v);add(v,u);
}
tarjan(,-); for(int i=;i<=n;i++)
if(!c[i]){
++dcc;
dfs1(i);
} for(int i=;i<tot;i++){
int x=e[i].to,y=e[i^].to;
if(c[x]!=c[y])
add_c(c[x],c[y]);
} dfs2(,); cout<<ans<<'\n';
}

边双联通分量缩点+树的直径——cf1000E的更多相关文章

  1. HDU5409---CRB and Graph 2015多校 双联通分量缩点

    题意:一个联通的无向图, 对于每一条边, 若删除该边后存在两点不可达,则输出这两个点, 如果存在多个则输出第一个点尽可能大,第二个点尽可能小的. 不存在输出0 0 首先 若删除某一条边后存在多个联通分 ...

  2. POJ3694 Network —— 边双联通分量 + 缩点 + LCA + 并查集

    题目链接:https://vjudge.net/problem/POJ-3694 A network administrator manages a large network. The networ ...

  3. POJ3177 Redundant Paths —— 边双联通分量 + 缩点

    题目链接:http://poj.org/problem?id=3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total ...

  4. POJ 3694Network(Tarjan边双联通分量 + 缩点 + LCA并查集维护)

    [题意]: 有N个结点M条边的图,有Q次操作,每次操作在点x, y之间加一条边,加完E(x, y)后还有几个桥(割边),每次操作会累积,影响下一次操作. [思路]: 先用Tarjan求出一开始总的桥的 ...

  5. 洛谷P2860 [USACO06JAN]冗余路径Redundant Paths(tarjan求边双联通分量)

    题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1. ...

  6. Spoj 2878 KNIGHTS - Knights of the Round Table | 双联通分量 二分图判定

    题目链接 考虑建立原图的补图,即如果两个骑士不互相憎恨,就在他们之间连一条无向边. 显而易见的是,如果若干个骑士在同一个点数为奇数的环上时,他们就可以在一起开会.换句话说,如果一个骑士被一个奇环包含, ...

  7. 【UVA10972】RevolC FaeLoN (求边双联通分量)

    题意: 给你一个无向图,要求把所有无向边改成有向边,并且添加最少的有向边,使得新的有向图强联通. 分析: 这题的解法还是很好想的.先用边双联通分量缩点,然后找新图中入度为0和为1的点,入度为0则ans ...

  8. [J]computer network tarjan边双联通分量+树的直径

    https://odzkskevi.qnssl.com/b660f16d70db1969261cd8b11235ec99?v=1537580031 [2012-2013 ACM Central Reg ...

  9. BZOJ 压力 tarjan 点双联通分量+树上差分+圆方树

    题意 如今,路由器和交换机构建起了互联网的骨架.处在互联网的骨干位置的核心路由器典型的要处理100Gbit/s的网络流量. 他们每天都生活在巨大的压力之下.小强建立了一个模型.这世界上有N个网络设备, ...

随机推荐

  1. 内网渗透_linux_socks代理_reGeorg+proxychains

    过程演示 测试前提是目标服务器已经getshell. 1.将 reGeorgSocksProxy 中的 tunnel.jsp 文件放置到目标服务器web目录,查看能否正常访问(如图). 2.设置kal ...

  2. add a characteristic in enovia PLM

    Problem: add a new Char. name D_COI6 that the description is Injected coloration #7 (COI6) in the D_ ...

  3. 微信公众号开发上传图文素材带有卡片小程序报错:errcode=45166,errmsg = invalid content hint

    微信公众号开发自从支持允许在群发图文中插入小程序,方便了小程序的运营及推广.最近在三方服务开发中,要支持图文素材插入小程序遇到了一个很是棘手的问题.官方给出的插入小程序的示例支持文字.图片.卡片.如下 ...

  4. matlab计时超好用

    方法一: profile on <body?> profile viewer 会把所有代码的时间,都显示出来,每行每个函数用时统计,一目了然: 方法二: tic; <body-par ...

  5. bootstrapValidator--表单校验

    关于表单校验 要依次引入 <link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css"& ...

  6. 2019.7.3模拟 七星连珠(行列式+随机+k进制FWT)

    题目大意: 给一个\(n*n\)的矩阵,对于所有排列p,记录\(a[i][p[i]]\)的k进制下不进位加法的结果,问所有被记录过的数. \(n<=50,p=2.3,0<=a[i][j]& ...

  7. CRI 与 ShimV2:一种 Kubernetes 集成容器运行时的新思路

    摘要: 关于 Kubernetes 接口化设计.CRI.容器运行时.shimv2.RuntimeClass 等关键技术特性的设计与实现.     Kubernetes 项目目前的重点发展方向,是为开发 ...

  8. windows启动redis失败

    # Warning: no config file specified, using the default config. In order to specify a config file use ...

  9. NX二次开发-UFUN判断文件是否存在UF_CFI_ask_file_exist

    #include <uf.h> #include <uf_ui.h> #include <uf_cfi.h> UF_initialize(); //判断文件是否存在 ...

  10. NX二次开发-UFUN更改图纸页比例UF_DRAW_set_drawing_info

    #include <uf.h> #include <uf_draw.h> #include <uf_part.h> UF_initialize(); //获得当前图 ...