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,先把这些换上的点的后继点都处理出来, ...
随机推荐
- Winform中上传、下载文件选择打开文件的位置
打开将要上传的文件 var fileName="";OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Mul ...
- ROS服务的理解
服务是节点之间通信的另一种方式,服务允许节点发起一个请求和接收一个响应. 打开终端在里面输入: roscore 查看当前的运行节点: rosnode list 返回结果: /rosout 查看当前的运 ...
- leetcode Reverse Integer python
class Solution(object): def reverse(self, x): """ :type x: int :rtype: int "&quo ...
- Hadoop学习之Mapreduce执行过程详解
一.MapReduce执行过程 MapReduce运行时,首先通过Map读取HDFS中的数据,然后经过拆分,将每个文件中的每行数据分拆成键值对,最后输出作为Reduce的输入,大体执行流程如下图所示: ...
- 不包含任何UserControl
奇怪了,以前做控件的时候都没有这个问题,哎,又堕落了1年,什么都忘了 创建自定义控件 可以继承现有控件,也可以继承userContrl类,但是现在有个问题 很多网上的资料说,啊,直接创建一个自定义控件 ...
- codeforces 589F. Gourmet and Banquet 二分+网络流
题目链接 给你n种菜, 每一种可以开始吃的时间不一样, 结束的时间也不一样. 求每种菜吃的时间都相同的最大的时间.时间的范围是0-10000. 看到这个题明显可以想到网络流, 但是时间的范围明显不允许 ...
- 富文本编辑器ckeditor继承
新建一个web项目ckfinder,导入lib包 加入java包,编码格式UTF-8 在WebRoot下添加ckedtior以及ckfinder两个文件夹,将config.xml拷入WEB-INF中 ...
- querySelectorAll 和 jQuery选择器
参考 http://xahlee.info/js/jquery_diff_querySelectorAll.html http://stackoverflow.com/questions/115035 ...
- MYSQL ERROR 1045 (28000): Access denied for user 'neeky'@'Nee' (using password: YES)
情况: mysql -h 192.168.1.7 -u neeky -p 本来这样就可以连接上mysql服务的了, 可是它会报这个错“ERROR 1045 (28000): Access denied ...
- 修改win7注册表发挥大容量内存优势
现在请打开注册表编辑器,找到[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control \Session Manager\MomoryManagement ...