首页 技术 正文
技术 2022年11月14日
0 收藏 745 点赞 2,529 浏览 1352 个字

又写了一遍,发出来做个记录

#include<cstdio>
#include<algorithm>
#include<iostream>using namespace std;#define N 500001int tot=,front[N],to[N<<],nxt[N<<];int id,dfn[N],low[N];int fa[N],dep[N];int dp[N];
int tmp[N],q[N];int ans;void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
}void add(int u,int v)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot;
}void circle(int x,int y)
{
int cnt=dep[y]-dep[x]+;
int now=y;
while(dfn[fa[now]]>=dfn[x]) tmp[cnt--]=now,now=fa[now];
tmp[cnt]=now;
cnt=dep[y]-dep[x]+;
int nn=cnt;
for(int i=;i<=cnt;++i) tmp[++nn]=tmp[i];
int h=,t=;
for(int i=;i<=nn;++i)
{
while(h<t && i-q[h]>cnt/) h++;
if(h<t) ans=max(ans,dp[tmp[q[h]]]+dp[tmp[i]]+i-q[h]);
while(h<t && dp[tmp[i]]-i>dp[tmp[q[t-]]]-q[t-]) t--;
q[t++]=i;
}
for(int i=;i<=cnt;++i) dp[x]=max(dp[x],dp[tmp[i]]+min(i-,cnt-i+));
}void tarjan(int x,int y)
{
dfn[x]=low[x]=++id;
int t;
for(int i=front[x];i;i=nxt[i])
{
if(i==(y^)) continue;
t=to[i];
if(!dfn[t])
{
fa[t]=x;
dep[t]=dep[x]+;
tarjan(t,i);
low[x]=min(low[x],low[t]);
}
else low[x]=min(low[x],dfn[t]);
if(dfn[x]<low[t])
{
ans=max(ans,dp[x]+dp[t]+);
dp[x]=max(dp[x],dp[t]+);
}
}
for(int i=front[x];i;i=nxt[i])
{
if(i==(y^)) continue;
t=to[i];
if(fa[t]!=x && dfn[x]<dfn[t]) circle(x,t);
}
}int main()
{
int n,m;
read(n); read(m);
int k,x,last;
while(m--)
{
read(k);
read(last);
while(--k)
{
read(x);
add(last,x);
last=x;
}
}
tarjan(,);
printf("%d",ans);
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905