hdu4916 Count on the path
调了好久。。。。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
using namespace std;
const int xxx=;
int n,m,head[xxx],Next[xxx<<],zhi[xxx<<],fa[xxx],ed;
int g[xxx][],f[][],dui[xxx],F[xxx],dp[xxx],xiao[];
void add(int a,int b)
{
Next[++ed]=head[a],head[a]=ed,zhi[ed]=b;
Next[++ed]=head[b],head[b]=ed,zhi[ed]=a;
}
const int L=1e7;
char in[L],*In,*End;
char getc(){
if(In==End){
End=in+fread(in,,L,stdin);
if(in==End) return ;
In=in;
}
return *In++;
}
int inin(int &x){
static char c;
for(;c=getc(),!isdigit(c) && c;);
if(!c) return ;
for(x=;isdigit(c);c=getc()) (x*=)+=c-'';
return ;
}
void dfs(int x)
{
g[x][]=;g[x][]=;
for(int i=head[x];i;i=Next[i])if(zhi[i]!=fa[x])
{
fa[zhi[i]]=x;
dfs(zhi[i]);
int temp=min(g[zhi[i]][],zhi[i]);
if(temp<=g[x][])
g[x][]=g[x][],
g[x][]=temp;
else g[x][]=min(g[x][],temp);
// else g[x][1]=min(g[x][1],g[zhi[i]][0]);
}
}
void dfsxxx(int x,int t)
{
dui[x]=t;
for(int i=head[x];i;i=Next[i])if(zhi[i]!=fa[x])
dfsxxx(zhi[i],t);
}
void dfs2(int x)
{
if(x>&&fa[x]!=)
if(g[fa[x]][]==min(g[x][],x))
F[x]=min(F[fa[x]],g[fa[x]][]);
else F[x]=min(F[fa[x]],g[fa[x]][]);else ;
if(fa[x]==)F[x]=;
dp[x]=min(F[x],g[x][]);
for(int i=head[x];i;i=Next[i])if(zhi[i]!=fa[x])
dfs2(zhi[i]);
}
//void dfs3(int x)
//{
// for(int i=head[x];i;i=Next[i])if(zhi[i]!=fa[x])
// dfs3(zhi[i]);
//}
int hhh(int x)
{
x=dui[x];
if(min(x,g[x][])==xiao[])return ;
else if(min(x,g[x][])==xiao[])return ;
else if(min(x,g[x][])==xiao[])return ;
else return ;
}
int pre=;
int main()
{
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
while(inin(n))
{
inin(m);
pre=;
memset(head,,sizeof(head));ed=;
re(i,,n)
{
int a,b;
// scanf("%d%d",&a,&b);
inin(a),inin(b);
add(a,b);
}
dfs();
xiao[]=xiao[]=xiao[]=n+;
for(int i=head[];i;i=Next[i])
{
dfsxxx(zhi[i],zhi[i]);
int temp=min(g[zhi[i]][],zhi[i]);
if(xiao[]>temp)
xiao[]=xiao[],
xiao[]=xiao[],
xiao[]=temp;
else if(xiao[]>temp)
xiao[]=xiao[],
xiao[]=temp;
else if(xiao[]>temp)
xiao[]=temp;
}
f[][]=xiao[];
f[][]=f[][]=xiao[],f[][]=f[][]=xiao[],f[][]=f[][]=xiao[];
f[][]=f[][]=xiao[],f[][]=f[][]=xiao[],f[][]=f[][]=xiao[];
dfs2();
// dfs3(1);
dui[]=-;
re(i,,m)
{
int a,b;
// scanf("%d%d",&a,&b);
inin(a),inin(b);
a=a^pre,b=b^pre;
if(a==)a++;if(b==)b++;if(a>n)a=a%n+;if(b>n)b=b%n+;
// printf("%d %d %d\n",a,b,pre);
if(dui[a]==dui[b]&&dui[a]!=-){pre=;}
else if(a==)
if(b==){pre=xiao[];}
else
{
int now=hhh(b);
re(i,,)if(i!=now){pre=min(dp[b],xiao[i]);break;}
}
else if(b==)
{
int now=hhh(a);
re(i,,)if(i!=now){pre=min(dp[a],xiao[i]);break;}
}
else {pre=min(min(dp[a],dp[b]),f[hhh(a)][hhh(b)]);}
printf("%d\n",pre);
}
}
return ;
}
hdu4916 Count on the path的更多相关文章
- HDU4916 Count on the path(树dp??)
这道题的题意其实有点略晦涩,定义f(a,b)为 minimum of vertices not on the path between vertices a and b. 其实它加一个minimum ...
- Count on the path
Count on the path Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDU 4916 Count on the path
意甲冠军: 考虑到一棵树,m询价 不要求回答每一次询价u和v通过在两个节点形成的最低等级点路径 思路: 一開始以为是LCA- 只是T了好几次- 后来发现不用LCA也可做 考虑每一个询问u和v ...
- [LeetCode] Longest Univalue Path 最长相同值路径
Given a binary tree, find the length of the longest path where each node in the path has the same va ...
- [Swift]LeetCode71. 简化路径 | Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...
- php 生成word的三种方式
原文地址 http://www.jb51.net/article/97253.htm 最近工作遇到关于生成word的问题 现在总结一下生成word的三种方法. btw:好像只要是标题带PHP的貌似点击 ...
- WPF 自定义雷达图
自定义雷达图表如下: Git下载地址:https://github.com/Kybs0/RadarChartControl 1.创建UserControl,名为“RadarChartControl” ...
- WPF Tookit Chart
如何使用Chart 实例: Binding数据源中是一个KeyValuePair对象.可以是Dictionary. <charting:Chart x:Name="chtSumma ...
- Proj.4 API 中文参考
ProjAPI https://github.com/OSGeo/proj.4/wiki/ProjAPI Tom Kralidis在2015年5月27日编辑此页·修订4 简介 执行pj_init()选 ...
随机推荐
- Windows更新导致的打印问题
最近很多BarTender用户都出现了打印问题,如3700错误消息及3721错误消息.这个问题存在于BarTender的所有版本,这主要是因为什么?又该如何去解决呢? 根据BarTender英文官网提 ...
- [sqoop] sqoop2 使用
sqoop版本1.99.7 ,安装省略 1. 启动server sqoop2-server start 2. sqoop2-shell 链接 表示安装成功. 创建link 查看link 创建job 查 ...
- windows pm2 启动nodejs失败:Error: EBADF: bad file descriptor, uv_pipe_open
windows下打开命令窗口,安装pm2:npm install pm2 -g pm2成功安装,在项目目录下用pm2启动服务:pm2 start index.js,结果启动失败,错误如下: .pm2\ ...
- TortoiseGit功能介绍
TortoiseGit功能介绍 使用方便 强大的提交对话框 每个项目设置 最小日志消息长度,以避免意外提交空日志消息 用于拼写检查的语言 与问题跟踪系统集成 有用的工具 有多种语言版本 Tortois ...
- Keil不能跳转到函数的定义怎么办
有时候我们右键一个函数名并点击Go To Definition Of xxx时,Keil却提示无法找到定义.但这个函数确实有定义的.这个时候可以试着重新编译整个工程,即可跳转到定义了.
- windows系统关闭某个端口的服务(以443端口为例子)
1.查看443被什么服务占用 netstat -ano | findstr 443 查看到443端口被pid为5140的服务占用了 2.去到任务管理器->任务 找到PID为5140的服务,然后停 ...
- java爬取网站信息和url实例
https://blog.csdn.net/weixin_38409425/article/details/78616688(出自此為博主) 具體代碼如下: import java.io.Buffer ...
- MUI学习01-顶部导航栏
建议:先看一下MUI注意事项 连接:http://ask.dcloud.net.cn/article/122 固定栏靠前 所谓的固定栏,也就是带有.mui-bar属性的节点,都是基于fixed定位的元 ...
- Excel GET.CELL说明
GET是得到的意思CELL是单元格的意思 --->那么它的意思就是你想得到单元格的什么东西(信息) 函数定义: GET.CELL(类型号,单元格(或范围)) 其中类型号,即你想要得到的信 ...
- partial_sum
版本1: template < class InputIterator, class OutputIterator > OutputIterator partial_sum(InputIt ...