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()选 ...
随机推荐
- Linux常见问题整理
1. 操作系统应该要控制硬件的哪些单元? 运算单元.控制单元.寄存器组.总线接口单元.输入/输出接口单元. 2. 一个较为完整的操作系统应该包含哪些部分? 比较完整的操作系统应该包含两个组件,一个是核 ...
- Kafka集群管理工具kafka-manager的安装使用
一.kafka-manager简介 kafka-manager是目前最受欢迎的kafka集群管理工具,最早由雅虎开源,用户可以在Web界面执行一些简单的集群管理操作.具体支持以下内容: 管理多个集群 ...
- 【Zookeeper系列】ZooKeeper伸缩性(转)
原文地址:https://www.cnblogs.com/sunddenly/p/4143306.html 一.ZooKeeper中Observer 1.1 ZooKeeper角色 经过前面的介绍,我 ...
- C# 不安装Oracle客户端情况下,如何连接到Oracle数据库
简介: 在我们开发应用场景经常碰到需要连接Oracle数据库,这也是相当常见的一种情况.一般.Net环境连接Oracle数据库,可以通过TNS/SQL.NET 配置文件,而 TNS 必须要 Oracl ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- .Net逆向初学习
前一段时间逆向一个程序时发现是.net的,然后用OD和IDA都调试不了,最后上网查了一下原来.net的逆向要用专门的工具.这里推荐大家一篇文章去了解一下逆向.net的一些工具简介:http://www ...
- 补充:CSS选择器样式的规范!
css----页面样式,美化页面 css样式的三个规则 1内联式:直接写在html标签中 <p style="color:red"> 直接对html标签使用 style ...
- JACKSON详解
Jackson 框架,轻易转换JSON Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 前面有介绍过json-lib这个框架,在 ...
- 测量应用程序cass和cad的使用感受
作为一名测绘工程专业的学生,在现在的电子信息时代是会经常与测量绘图有关的软件打交道的,如今我也算是接触绘图软件一年多了并且在上学期学校还组织我们大家一起进行了几周CAD集训,而且在校园和井陉的暑期实训 ...
- JavaScript基础知识(函数)
函数的基础 函数: 把实现相同功能的代码放到一个函数体中,当想实现这个功能时,直接执行这个函数即可:减少了的冗余:高内聚,低耦合--> 函数的封装: 函数:引用数据类型: var a = 10; ...