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序最小的点. 对答 ...
随机推荐
- 批处理修改Hosts文件
@echo off set stHosts=127.0.0.1 www.XXX.com FOR /F "eol=# tokens=1 delims=" %%i in (%Syste ...
- 关于Unity物理事件的执行顺序的最新理解
物体A: public class A:{ B b; void FixedUpdate(){ if(input.GetKeyDow(Keycode.I)) { collider.enable=fals ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- C++ 实验 使用重载运算符实现一个复数类
实验目的: 1.掌握用成员函数重载运算符的方法 2.掌握用友元函数重载运算符的方法 实验要求: 1.定义一个复数类,描述一些必须的成员函数,如:构造函数,析构函数,赋值函数,返回数据成员值的函数等. ...
- 《口算大作战 2》DLC:算法真奇妙
211614331 王诚荣 211614354 陈斌 --第一次结对作业 DLC DLC:三年级混合运算模块现已更新!现在您可以愉快的使用三年级题库啦.同时您必须拥有本体才能使用此DLC 单击此处查看 ...
- springmvc关于redisCluster的使用及配置
首先附上maven仓库jar包的下载地址:https://repo.spring.io/webapp/#/artifacts/browse/tree/General/libs-release-loca ...
- Beta 冲刺 二
团队成员 051601135 岳冠宇 031602629 刘意晗 031602248 郑智文 031602330 苏芳锃 031602234 王淇 照片 项目进展 岳冠宇 昨天的困难 fragment ...
- 12th final 发布评价II
1.约跑App——nice!:用户界面很是赏心悦目,给人一种很放松的感觉,与App的主题很配合,同时也在本周内把同学提出的bug都很好地完善了,而且采用了摄像头进行发布,整个发布过程清晰明朗不少.把约 ...
- PAT 1064 朋友数
https://pintia.cn/problem-sets/994805260223102976/problems/994805267416334336 如果两个整数各位数字的和是一样的,则被称为是 ...
- Oracle client 使用 .net程序连接 数据库时 出现 8.1.7 的解决办法
1. GS产品 连接oracle数据库时出现错误图示 2. 其实解决这个问题的办法很简单 一般是 修改一下 Oracle的app 目录的权限 最简单的办法是增加 everyone 权限 然后重启机器即 ...