AC日记——825G - Tree Queries
思路:
神题,路径拆成半链;
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 1000005
#define INF 0x3f3f3f3f
int n,m,val[maxn],head[maxn],E[maxn<<],V[maxn<<];
int cnt,root,last,ans=INF;
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
void dfs(int now,int fa,int Min)
{
val[now]=min(now,Min),Min=min(now,Min);
for(int i=head[now];i;i=E[i])
{
if(fa==V[i]) continue;
dfs(V[i],now,Min);
}
}
int main()
{
//freopen("data.txt","r",stdin);
in(n),in(m);int u,v;
for(int i=;i<n;i++)
{
in(u),in(v);
E[++cnt]=head[u],V[cnt]=v,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,head[v]=cnt;
}
in(root),in(root),root=root%n+,dfs(root,,INF);
for(int i=;i<m;i++)
{
in(u),in(v);
v=(last+v)%n+;
if(u==) ans=min(val[v],ans);
if(u==) last=min(ans,val[v]),printf("%d\n",last);
}
return ;
}
AC日记——825G - Tree Queries的更多相关文章
- AC日记——Propagating tree Codeforces 383c
C. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CodeForces 825G"Tree Queries"(选根建树)
传送门 •参考资料 [1]:CodeForces 825G Educational Round #25 G :建树选根大法+O1大法+iostream解绑了还是慢 •题意 给定一颗包含 n 个节点的树 ...
- AC日记——codevs1688求逆序对
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
- Codeforces 960D - Full Binary Tree Queries
960D - Full Binary Tree Queries 思路: 用move1[i]记录第i层第1种操作移动的个数(对这一层的个数取模) 用move2[i]记录第i层第2种操作移动的个数(对这一 ...
- CF1328E Tree Queries
CF1328E Tree Queries 应该还是比较妙的 题意 给你一个树,然后多次询问 每次询问给出一堆节点,问你是否能找到一个从根出发的链,是的对于给出的每个节点,都能找出链上的点,是的他们的距 ...
- E. Tree Queries 解析(思維、LCA)
Codeforce 1328 E. Tree Queries 解析(思維.LCA) 今天我們來看看CF1328E 題目連結 題目 給你一棵樹,並且給你\(m\le2e5\)個詢問(包含\(k\)個點) ...
- CF-1328 E. Tree Queries
E. Tree Queries 题目链接 题意 给定一个树,每次询问一组点,问是否存在一条从根到某点的路径,使得该组点到该路径的最短距离不超过1 分析 从根到达某点的路径,如果覆盖到了某个点,那么一定 ...
- AC日记——Tree poj 3237
Tree Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 9233 Accepted: 2431 Description ...
- AC日记——【模板】Link Cut Tree 洛谷 P3690
[模板]Link Cut Tree 思路: LCT模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 30 ...
随机推荐
- oracle的lpad()函数
lpad函数 lpad函数是Oracle数据库函数,lpad函数从左边对字符串使用指定的字符进行填充.从其字面意思也可以理解,l是left的简写,pad是填充的意思,所以lpad就是从左边填充的意思. ...
- 孙鑫视频VC++深入详解学习笔记
孙鑫视频VC++深入详解学习笔记 VC++深入详解学习笔记 Lesson1: Windows程序运行原理及程序编写流程 Lesson2: 掌握C++基本语法 Lesson3: MFC框架程序剖析 Le ...
- Codeforces 895.B XK Segments
B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- centos pure-ftpd配置及错误解决
使用yum安装pure-ftpd Pure-FTPd是Linux上的一个开源的FTP服务程序,在易用性.配置性上比vsftp较方便,下面我们使用centos6演示安装和配置pure-ftpd. 安装e ...
- plantuml使用教程【转】
plantuml使用教程[转] Table of Contents 前言 什么是PlantUML 在Emacs里配置PlantUML(参考:Run it from Emacs) 其他软件里的Pla ...
- 贪心+离散化+线段树上二分。。。 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest G. Of Zorcs and Axes
题目链接:http://codeforces.com/gym/101149/problem/G 题目大意:给你n对数字,为(a[i], b[i]),给你m对数字,为(w[i], c[i]).给n对数字 ...
- SPOJ DQUERY 离线树状数组+离散化
LINK 题意:给出$(n <= 30000)$个数,$q <= 2e5$个查询,每个查询要求给出$[l,r]$内不同元素的个数 思路:这题可用主席树查询历史版本的方法做,感觉这个比较容易 ...
- King's Sanctuary(简单几何)
King's Sanctuary Time Limit: 1000 ms Memory Limit: 65535 kB Solved: 111 Tried: 840 Submit Status Bes ...
- Codeforces Round #191 (Div. 2) A. Flipping Game(简单)
A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 安装HDP时的报错信息
1,安装ambari时报错:Bootstrap process timed out. It will be destroyed. 报错原因:/etc/sudoers文件中未设置免密权限 解决办法:ha ...