BZOJ 1023
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的更多相关文章
- bzoj 1023: [SHOI2008]cactus仙人掌图 tarjan缩环&&环上单调队列
1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1141 Solved: 435[Submit][ ...
- BZOJ 1023 仙人掌图
Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回 ...
- [BZOJ]1023 cactus仙人掌图(SHOI2008)
NOIP后的第一次更新嗯. Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌图(cactus).所谓简单回路就是指在 ...
- bzoj 1023: [SHOI2008]cactus仙人掌图 2125: 最短路 4728: 挪威的森林 静态仙人掌上路径长度的维护系列
%%% http://immortalco.blog.uoj.ac/blog/1955 一个通用的写法是建树,对每个环建一个新点,去掉环上的边,原先环上每个点到新点连边,边权为点到环根的最短/长路长度 ...
- BZOJ 1023: [SHOI2008]cactus仙人掌图 | 在仙人掌上跑DP
题目: 求仙人掌直径 http://www.lydsy.com/JudgeOnline/problem.php?id=1023 题解: 首先给出仙人掌的定义:满足所有的边至多在一个环上的无向联通图 我 ...
- SHOI 2007 仙人掌图(BZOJ 1023)
1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2564 Solved: 1062 Descrip ...
- bzoj 1023 [SHOI2008]cactus仙人掌图 ( poj 3567 Cactus Reloaded )——仙人掌直径模板
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1023 http://poj.org/problem?id=3567 因为lyd在讲课,所以有 ...
- 【BZOJ 1023】[SHOI2008]cactus仙人掌图
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1023 [题意] [题解] 如果不考虑有环的情况; 那么有一个经典的求树的直径的方法; ...
- 【BZOJ 1023】【SHOI 2008】cactus仙人掌图
良心的题解↓ http://z55250825.blog.163.com/blog/static/150230809201412793151890/ tarjan的时候如果是树边则做树形DP(遇到环就 ...
- bzoj 1023: [SHOI2008]cactus仙人掌图
这道题是我做的第一道仙人掌DP,小小纪念一下…… 仙人掌DP就是环上的点环状DP,树上的点树上DP.就是说,做一遍DFS,DFS的过程中处理出环,环上的点先不DP,先把这些换上的点的后继点都处理出来, ...
随机推荐
- iOS隐藏tabBar的方法
两种方法用来隐藏tabBar 1.在本页面隐藏 #pragma mark - 隐藏tabBar - (void)viewWillAppear:(BOOL)animated{ self.tabBarCo ...
- <jsp:directive.page>标签
directive 英 [dɪ'rektɪv; daɪ-] 美 [daɪ'rɛktɪv] n. 指示:指令 adj. 指导的:管理的 等效于 <%page import="com.ct ...
- BZOJ 1406: [AHOI2007]密码箱( 数论 )
(x+1)(x-1) mod N = 0, 枚举N的>N^0.5的约数当作x+1或者x-1... ------------------------------------------------ ...
- USACO Section 4.2 The Perfect Stall(二分图匹配)
二分图的最大匹配.我是用最大流求解.加个源点s和汇点t:s和每只cow.每个stall和t 连一条容量为1有向边,每只cow和stall(that the cow is willing to prod ...
- Java学习之利用集合发牌小练习
/* * 思路: * A:创建一个HashMap集合 * B:创建一个ArrayList集合 * C:创建花色数组和点数数组 * D:从0开始往HashMap里面存储编号,并存储对应的牌同时往Arra ...
- 【原创】Libjpeg 库使用心得(一) JPEG图像DCT系数的获取和访问
[原创]继续我的项目研究,现在采用Libjpeg库函数来进行处理,看了库函数之后发现C语言被这些人用的太牛了,五体投地啊...废话不多说,下面就进入正题. Libjpeg库在网上下载还是挺方便的,这里 ...
- When Is Cheryl's Birthday
大早上起来逛微博,看见@西瓜大丸子汤Po的一个逻辑题,遂点开看之... 原文链接:http://nbviewer.ipython.org/url/norvig.com/ipython/Cheryl.i ...
- hdu 5461 Largest Point
Thinking about it: 对于式子 a * ti * ti + b * tj,可以看作时有两部分构成 a * ti * ti 和 b * tj,如果整个式子要最大,则要求这两部分都要尽量大 ...
- javascript - Show mouse cursor in phantom.js - Stack Overflow
javascript - Show mouse cursor in phantom.js - Stack Overflow Show mouse cursor in phantom.js
- UBER人民优步司机注册攻略
注意:本文驾驶证行驶证图片为本人拍摄,请广大网友勿作它用 转载请修改! 详细的介绍注册优步uber司机端步骤; uber对司机的要求: 车辆为本地牌照 车龄在5年以内 裸车价格在10万以上 目 ...