bzoj千题计划224:bzoj1023: [SHOI2008]cactus仙人掌图
又写了一遍,发出来做个记录
#include<cstdio>
#include<algorithm>
#include<iostream> using namespace std; #define N 500001 int 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);
}
bzoj千题计划224:bzoj1023: [SHOI2008]cactus仙人掌图的更多相关文章
- bzoj千题计划113:bzoj1023: [SHOI2008]cactus仙人掌图
http://www.lydsy.com/JudgeOnline/problem.php?id=1023 dp[x] 表示以x为端点的最长链 子节点与x不在同一个环上,那就是两条最长半链长度 子节点与 ...
- BZOJ1023: [SHOI2008]cactus仙人掌图(仙人掌dp)
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3467 Solved: 1438[Submit][Status][Discuss] Descripti ...
- BZOJ1023[SHOI2008]cactus仙人掌图 【仙人掌DP】
题目 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌 图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回路. 举例来说 ...
- BZOJ1023: [SHOI2008]cactus仙人掌图(仙人掌)
Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的 ...
- BZOJ1023:[SHOI2008]cactus仙人掌图(圆方树,DP,单调队列)
Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌图(cactus). 所谓简单回路就是指在图上不重复经过任何一个顶点 ...
- bzoj千题计划175:bzoj1303: [CQOI2009]中位数图
http://www.lydsy.com/JudgeOnline/problem.php?id=1303 令c[i]表示前i个数中,比d大的数与比d小的数的差,那么如果c[l]=c[r],则[l+1, ...
- [bzoj1023][SHOI2008]cactus 仙人掌图 (动态规划)
Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回 ...
- bzoj1023: [SHOI2008]cactus仙人掌图
学习了一下圆方树. 圆方树是一种可以处理仙人掌的数据结构,具体见这里:http://immortalco.blog.uoj.ac/blog/1955 简单来讲它是这么做的:用tarjan找环,然后对每 ...
- 2018.10.29 bzoj1023: [SHOI2008]cactus仙人掌图(仙人掌+单调队列优化dp)
传送门 求仙人掌的直径. 感觉不是很难. 分点在环上面和不在环上分类讨论. 不在环上直接树形dpdpdp. 然后如果在环上讨论一波. 首先对环的祖先有贡献的只有环上dfsdfsdfs序最小的点. 对答 ...
随机推荐
- [Direct2D开发] 绘制网格
转载请注明出处:http://www.cnblogs.com/Ray1024 一.引言 最近在使用Direct2D进行绘制工作中,需要实现使用Direct2D绘制网格的功能.在网上查了很多资料,终于实 ...
- Excel读取Word Table元素
Option Explicit Sub Mian() Application.ScreenUpdating = False Application.DisplayAlerts = False Appl ...
- 20135327郭皓--Linux内核分析第三周 构造一个简单的Linux系统MenuOS
Linux内核分析第三周 构造一个简单的Linux系统MenuOS 前提回顾 1.计算机是如何工作的三个法宝 1.存储程序计算机 2.函数调用堆栈 3.中断 2.操作系统的两把宝剑 中断上下文的切换 ...
- C++:派生类的构造函数和析构函数的调用顺序
一.派生类 在C++编程中,我们在编写一个基类的派生类时,大致可以分为四步: • 吸收基类的成员:不论是数据成员还是函数成员,派生类吸收除基类的构造函数和析构函数之外的全部成员. • 改造基类函数:在 ...
- hadoop-2.7.2 分布式集群搭建
1.机器信息 五台centos 64位机器 2.集群规划 Server Name Hadoop Cluster Zookeeper Ensemble HBase Cluster Hadoop01 ...
- PAT----1001. A+B Format (20)解题过程
1001. A+B Format (20) github链接 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B Calculate a + b and output t ...
- 第四,五周——Java编写的电梯模拟系统(结对作业)
作业代码:https://coding.net/u/liyi175/p/Dianti/git 伙伴成员:石开洪 http://www.cnblogs.com/shikaihong/(博客) 这次的作业 ...
- Android map转json格式,附上Jackson包下载地址,导入过程
android中的map转json,需要下载jackson包,下载地址: http://www.java2s.com/Code/Jar/j/Downloadjacksonall199jar.htm 下 ...
- [转帖] K8S 常用命令
k8s常用命令 原贴地址 查看集群信息: [root@kubernetes-master pods]# kubectl cluster-info kubectl cluster-info展示结果 k ...
- 转帖 OKR
什么是OKR OKR全称是Objectives and Key Results,即目标与关键成果法.OKR是一套定义和跟踪目标及其完成情况的管理工具和方法.1999年Intel公司发明了这种方法,后来 ...