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. 转 --maven系列之一 简介

    http://blog.csdn.net/jiuqiyuliang/article/details/41076215 [项目管理和构建]——Maven简介(一) 2015-01-31 21:27 68 ...

  2. poj2407---欧拉函数应用

    欧拉函数介绍: 在数论中,对正整数n,欧拉函数是少于或等于n你的数中与n互质的数的数目. 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中 ...

  3. BZOJ 1974: [Sdoi2010]auction 代码拍卖会( dp )

    在1, 11, 111……中选<=8个, + 11..(n个1)拼出所有可能...这些数mod p至多有p中可能, 找出循环的处理一下. 那么dp就很显然了...dp(i, j, k)表示前i种 ...

  4. Hive学习之更改表的属性

    1.修改表名    alter table table_name rename to new_table_name;2.修改列名    alter table tablename change col ...

  5. java.el.PropertyNotFoundException解决方法

    今天在开发中遇到了java.el.PropertyNotFoundException异常,检查JSP页面.Action.Bean.都没有发现错误 在网上搜了一下可能是我的bean不是一个标准的bean ...

  6. codeforces 632D. Longest Subsequence 筛法

    题目链接 记录小于等于m的数出现的次数, 然后从后往前筛, 具体看代码. #include <iostream> #include <vector> #include < ...

  7. nodejs中EventEmitter

    在模块events中,定义了一个EventEmitter类,可以使用var EventEmitter = require('events');访问它.基本上所有发送事件的对象都是继承自EventEmi ...

  8. 为什么要for循环以及for循环的流程

    /* Name:为什么需要循环以及for循环流程 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月10日 03:16:55 Description:求1 ...

  9. (Problem 92)Square digit chains

    A number chain is created by continuously adding the square of the digits in a number to form a new ...

  10. Telnet自动登录

    http://zw7534313.iteye.com/blog/1603808 http://network.51cto.com/art/201007/212255_all.htm (s=`stty ...