program bzoj1023;
uses math; const inf=;
maxn=;
maxm=; type edge=record
togo,next:longint;
end; var n,m,cnt,ind,ans,l,r:longint;
last,deep,f,low,dfn,fa:array [..maxn] of longint;
a,q:array [..maxn*] of longint;
e:array [..maxm] of edge; procedure insert(u,v:longint);
begin
inc(cnt);
e[cnt].togo:=v; e[cnt].next:=last[u]; last[u]:=cnt;
inc(cnt);
e[cnt].togo:=u; e[cnt].next:=last[v]; last[v]:=cnt;
end; procedure dp(root,x:longint);
var tot,i:longint;
begin
tot:=deep[x]-deep[root]+;
i:=x;
while i<>root do
begin
a[tot]:=f[i];
dec(tot);
i:=fa[i];
end;
a[tot]:=f[root];
tot:=deep[x]-deep[root]+;
for i:= to tot do
a[i+tot]:=a[i];
q[]:=; l:=; r:=;
for i:= to (tot shl ) do
begin
while (l<=r) and (i-q[l]>(tot shr )) do
inc(l);
ans:=max(ans,a[i]+i+a[q[l]]-q[l]);
while (l<=r) and (a[q[r]]-q[r]<=a[i]-i) do
dec(r);
inc(r);
q[r]:=i;
end;
for i:= to tot do
f[tot]:=max(f[root],a[i]+min(i-,tot-i+));
end; procedure dfs(x:longint);
var i:longint;
begin
inc(ind);
low[x]:=ind;
dfn[x]:=ind;
i:=last[x];
while i<> do
begin
if e[i].togo<>fa[x] then
begin
if dfn[e[i].togo]= then
begin
fa[e[i].togo]:=x;
deep[e[i].togo]:=deep[x]+;
dfs(e[i].togo);
low[x]:=min(low[x],low[e[i].togo]);
end
else
low[x]:=min(low[x],dfn[e[i].togo]);
if dfn[x]<low[e[i].togo] then
begin
ans:=max(ans,f[x]+f[e[i].togo]+);
f[x]:=max(f[x],f[e[i].togo]+);
end;
end;
i:=e[i].next;
end;
i:=last[x];
while i<> do
begin
if (fa[e[i].togo]<>x) and (dfn[x]<dfn[e[i].togo]) then
dp(x,e[i].togo);
i:=e[i].next;
end;
end; procedure main;
var i,j,a,b,k:longint;
begin
read(n,m);
for i:= to m do
begin
read(k,a);
for j:= to k do
begin
read(b);
insert(a,b);
a:=b;
end;
end;
dfs();
writeln(ans);
end; begin
main;
end.

BZOJ 1023的更多相关文章

  1. bzoj 1023: [SHOI2008]cactus仙人掌图 tarjan缩环&&环上单调队列

    1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1141  Solved: 435[Submit][ ...

  2. BZOJ 1023 仙人掌图

    Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回 ...

  3. [BZOJ]1023 cactus仙人掌图(SHOI2008)

    NOIP后的第一次更新嗯. Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌图(cactus).所谓简单回路就是指在 ...

  4. bzoj 1023: [SHOI2008]cactus仙人掌图 2125: 最短路 4728: 挪威的森林 静态仙人掌上路径长度的维护系列

    %%% http://immortalco.blog.uoj.ac/blog/1955 一个通用的写法是建树,对每个环建一个新点,去掉环上的边,原先环上每个点到新点连边,边权为点到环根的最短/长路长度 ...

  5. BZOJ 1023: [SHOI2008]cactus仙人掌图 | 在仙人掌上跑DP

    题目: 求仙人掌直径 http://www.lydsy.com/JudgeOnline/problem.php?id=1023 题解: 首先给出仙人掌的定义:满足所有的边至多在一个环上的无向联通图 我 ...

  6. SHOI 2007 仙人掌图(BZOJ 1023)

    1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2564  Solved: 1062 Descrip ...

  7. bzoj 1023 [SHOI2008]cactus仙人掌图 ( poj 3567 Cactus Reloaded )——仙人掌直径模板

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1023 http://poj.org/problem?id=3567 因为lyd在讲课,所以有 ...

  8. 【BZOJ 1023】[SHOI2008]cactus仙人掌图

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1023 [题意] [题解] 如果不考虑有环的情况; 那么有一个经典的求树的直径的方法; ...

  9. 【BZOJ 1023】【SHOI 2008】cactus仙人掌图

    良心的题解↓ http://z55250825.blog.163.com/blog/static/150230809201412793151890/ tarjan的时候如果是树边则做树形DP(遇到环就 ...

  10. bzoj 1023: [SHOI2008]cactus仙人掌图

    这道题是我做的第一道仙人掌DP,小小纪念一下…… 仙人掌DP就是环上的点环状DP,树上的点树上DP.就是说,做一遍DFS,DFS的过程中处理出环,环上的点先不DP,先把这些换上的点的后继点都处理出来, ...

随机推荐

  1. A - A

    A - A Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status ...

  2. UVALive 6709 - Mosaic 二维线段树

    题目链接 给一个n*n的方格, 每个方格有值. 每次询问, 给出三个数x, y, l, 求出以x, y为中心的边长为l的正方形内的最大值与最小值, 输出(maxx+minn)/2, 并将x, y这个格 ...

  3. 学会了 C 语言真的可以开发出很多东西吗?

    马里奥碰到花朵就变身. 什么是马里奥?一个装着 16 × 32 个小色块的长方形,其中一些色块填着颜色,另一些没有.什么是花?一个 16 × 16 的正方形.什么是「变身」?把马里奥这个方块里面代表衣 ...

  4. Hadoop2.0安装

    http://blog.csdn.net/samhacker/article/details/18802223 http://blog.csdn.net/crazyhacking/article/de ...

  5. HDU 5019 Revenge of GCD

    题解:筛出约数,然后计算即可. #include <cstdio> #include <algorithm> typedef long long LL; LL a1[10000 ...

  6. 设计模式入门之桥接模式Bridge

    Abstraction:抽象部分的父类,定义须要实现的接口.维护对实现部分的引用,从而把实现桥接到Implementor中去 Implementor:实现部分的接口 RefinedAbstractio ...

  7. ostringstream的使用方法

    ostringstream的使用方法 [本文来自]http://www.builder.com.cn/2003/0304/83250.shtml http://www.cppblog.com/alan ...

  8. 在SSIS包中使用 Checkpoint从失败处重新启动包

    使用SSIS做ETL的过程中会遇到各种各样的错误,对于一些大数据量的Job失败以后我们不希望重新运行,因为重新运行的时间开销是非常大的,我们只希望从失败的部分开始运行,这样可以省去很多的时间. SSI ...

  9. js调试若干

    主要是将 chrome调试工具   firebug的控制台对以下都有支持 consoleAPI https://developers.google.com/chrome-developer-tools ...

  10. Foundation 框架 NSFileManager,NSData 简单的文件操作

    一.简单展示NSFileManager的使用 #import <Foundation/Foundation.h> int main(int argc, const char * argv[ ...