Nearest Common Ancestors POJ
来源:互联网 发布:人工智能的利弊辩论 编辑:程序博客网 时间:2024/05/21 09:02
模板题
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn=10005;int fa[maxn*4];void solve(int u,int v){ int fv=v; while(fa[u]!=u) { fv=v; while(fa[fv]!=fv) { if(u==fv) { printf("%d\n",u); return ; } fv=fa[fv]; } u=fa[u]; } printf("%d\n",u); return ;}int main(){ int t; scanf("%d",&t); while(t--) { int u,v; int n; scanf("%d",&n); for(int i=1; i<=n; i++) fa[i]=i; for(int i=1; i<n; i++) { scanf("%d%d",&u,&v); fa[v]=u; } scanf("%d%d",&u,&v); solve(u,v); }}
阅读全文
0 0
- POJ Nearest Common Ancestors
- Nearest Common Ancestors POJ
- POJ 1330 Nearest Common Ancestors
- poj 1330 Nearest Common Ancestors
- poj 1330 Nearest Common Ancestors
- POJ 1330 Nearest Common Ancestors
- POJ 1330 Nearest Common Ancestors
- POJ 1330 Nearest Common Ancestors
- poj - 1330 - Nearest Common Ancestors
- poj 1330 Nearest Common Ancestors
- poj 1330 Nearest Common Ancestors
- POJ 1330 Nearest Common Ancestors
- poj 1300Nearest Common Ancestors
- poj 1330 Nearest Common Ancestors
- poj 1330 Nearest Common Ancestors
- poj 1330 Nearest Common Ancestors
- POJ 1330:Nearest Common Ancestors
- POJ 1330 Nearest Common Ancestors
- iOS开发工具Xcode安装与使用
- 图文详解!嵌入式Linux内核启动主要分为这三个阶段
- Bootstrap踩坑经历
- C#3.0新特性
- springBoot+mybatis多数据源的配置
- Nearest Common Ancestors POJ
- 设计模式——使用模板方法模式尽量减少重复相似的代码段
- 数组Array和集合的区别
- Android.mk文件解读
- springboot(六):如何优雅的使用mybatis
- Charles使用教程
- Map 几个常用方法的比较
- Swagger使用总结
- 关于tomcat自带连接池dbcp的优化设置