codeforces825G Tree Queries
来源:互联网 发布:怎么做淘宝客服兼职 编辑:程序博客网 时间:2024/05/16 13:53
我们可以将第一个黑点作为树的根。
令
接下来考虑黑点
- 若
i 与j 的lca 是根,由于fi 已经统计过了,j 对i 的贡献就是fj - 若
i 与j 的lca 不是j ,j 对i 的贡献就是j 到lca 路径上点编号的最小值与i 到lca 路径上点编号的最小值。因为lca 一定在i 到根的路径上,贡献就是fj
那么黑点
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespace std;#define N 1000010vector<int>g[N];int i,j,k,n,m,p,a[N],q,x,y,Ans=1e9,Last;inline int Min(int x,int y){ return x<y?x:y;}inline void Dfs(int x,int f){ a[x]=Min(a[f],x); for(int i=0;i<g[x].size();i++) if(g[x][i]!=f)Dfs(g[x][i],x);}int main(){ scanf("%d%d",&n,&q);q--; memset(a,127,sizeof(a)); for(i=1;i<n;i++)scanf("%d%d",&x,&y),g[x].push_back(y),g[y].push_back(x); scanf("%d%d",&x,&y);y=y%n+1; Dfs(y,0); while(q--){ scanf("%d%d",&x,&y); y=(y+Last)%n+1; if(x==1)Ans=Min(Ans,a[y]);else Last=Min(Ans,a[y]),printf("%d\n",Last); } return 0;}
阅读全文
2 0
- codeforces825G Tree Queries
- [CF375D]Tree and Queries
- Codeforces 825 G Tree Queries
- UVA 12424 Answering Queries on a Tree
- codeforces 221 div1 D Tree and Queries
- [dsu] codeforces 375D. Tree and Queries
- codeforces 375D Tree and Queries
- [Codeforces375D]Tree and Queries(莫队+分块)
- Educational Codeforces Round 25 G. Tree Queries
- Codeforces 825G Tree Queries(DFS)
- Codeforces 375D Tree and Queries
- [Codeforces375D]Tree and Queries(dsu on the tree+bit)
- [codeforces375D]Tree and Queries(dsu on the tree+bit)
- HDU4027 Can you answer these queries?(Segment Tree)
- UVALive 5031 Graph and Queries(名次树 rank tree)
- CF 375D Tree and Queries(dfs序+分块查找)
- UVA 12424 Answering Queries on a Tree (树链剖分)
- Codeforces 375D:Tree and Queries 点化成区间 莫队
- Head First 设计模式 —— 工厂模式与工厂方法
- 如何利用PhotoBulk优化文件
- Initialization failed for 'https://start.spring.io' Please check URL, network and proxy settings.
- Wireshark基本介绍和学习TCP三次握手
- SmartGit(试用期30后),个人继续使用的方法。
- codeforces825G Tree Queries
- Java程序员必看的15本书的电子版下载地址
- Eclipse介绍
- 大数阶乘
- Android下的网络编程
- 解决eclipse中tomcat无法识别maven web项目问题
- 使用git和github管理自己的项目---基础操作学习
- Alpha混合技术——unity
- 免费分享:linux运维基础视频教程!