[bzoj4151][AMPPZ2014]The Cave
来自FallDream的博客,未经允许,请勿转载,谢谢。
#include<iostream>
#include<cstdio>
#define MN 300000
#define getchar() (*S++)
char B[<<],*S=B;
using namespace std;
inline int read()
{
int x = ; char ch = getchar();
while(ch < '' || ch > '') ch = getchar();
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x;
}
int head[MN+],n,m,cnt=,dep[MN+],a[MN+],fa[MN+],b[MN+],d[MN+];
struct edge{int to,next;}e[MN*+];
inline void ins(int f,int t)
{
e[++cnt]=(edge){t,head[f]};head[f]=cnt;
e[++cnt]=(edge){f,head[t]};head[t]=cnt;
} void Dfs(int x,int f)
{
fa[x]=f;
for(int i=head[x];i;i=e[i].next)
if(e[i].to!=f)
dep[e[i].to]=dep[x]+,Dfs(e[i].to,x);
} int main()
{
fread(B,,<<,stdin);
for(int T=read();T;--T)
{
n=read();m=read();cnt=;
for(register int i=;i<=n;++i) head[i]=;
for(register int i=;i<n;++i) ins(read(),read());
dep[]=;Dfs(,);int mx=,From=;
for(register int i=;i<=m;++i)
a[i]=read(),b[i]=read(),d[i]=read(),
(dep[a[i]]+dep[b[i]]-d[i]+)/>mx?(mx=(dep[a[i]]+dep[b[i]]-d[i]+)/,From=i):;
for(From=a[From];dep[From]>mx;From=fa[From]);
dep[From]=;Dfs(From,);bool flag=;
for(register int i=;i<=m;++i)
if(dep[a[i]]+dep[b[i]]>d[i]) {flag=;break;}
if(flag) printf("TAK %d\n",From);
else puts("NIE");
}
return ;
}
[bzoj4151][AMPPZ2014]The Cave的更多相关文章
- BZOJ.4151.[AMPPZ2014]The Cave(结论)
BZOJ 不是很懂他们为什么都要DFS三次.于是稳拿Rank1 qwq. (三道题两个Rank1一个Rank3效率是不是有点高qwq?) 记以\(1\)为根DFS时每个点的深度是\(dep_i\).对 ...
- XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--J.Cave
给你一棵树,现在有m个专家,每个专家计划从$a_i$走到$b_i$, 经过的距离不超过$d_i$,现在让你找一个点,使得所有专家的路途都能经过这个点 令$S_i$表示满足第i个专家的所有点,先检查1可 ...
- AMPPZ2014
[AMPPZ2014]The Lawyer 记录每天结束的最早的会议以及开始的最晚的会议即可. #include<cstdio> #define N 500010 int n,m,i,d, ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [BZOJ4151]The Cave
Solution: 假设现在在点1,有许多形如 (x, y, z) 的限制条件,那么对于一组限制,必须先走到 x, y 的 \(\frac{z-dis(x, y)}{2}\) 级祖先,叫这些点为限 ...
- BZOJ 4144: [AMPPZ2014]Petrol
4144: [AMPPZ2014]Petrol Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 457 Solved: 170[Submit][Sta ...
- 【BZOJ2049】 [Sdoi2008]Cave 洞穴勘测 LCT/并查集
两种方法: 1.LCT 第一次LCT,只有link-cut和询问,无限T,到COGS上找了数据,发现splay里的父亲特判出错了(MD纸张),A了,好奇的删了反转T了.... #include < ...
- 【bzoj2049】[Sdoi2008]Cave 洞穴勘测 link-cut-tree
2016-05-30 11:04:51 学习了link-cut-tree 二中神犇封禹的讲义感觉讲的超级清晰易懂啊(没有的可以q窝 算是模板吧 #include<bits/stdc++.h&g ...
- 循环队列+堆优化dijkstra最短路 BZOJ 4152: [AMPPZ2014]The Captain
循环队列基础知识 1.循环队列需要几个参数来确定 循环队列需要2个参数,front和rear 2.循环队列各个参数的含义 (1)队列初始化时,front和rear值都为零: (2)当队列不为空时,fr ...
随机推荐
- aws中的路由表
参考官方文档: 由表中包含一系列被称为路由的规则,可用于判断网络流量的导向目的地. 在您的 VPC 中的每个子网必须与一个路由表关联:路由表控制子网的路由.一个子网一次只能与一个路由表关联,但您可以将 ...
- RxSwift(一)
文/iOS_Deve(简书作者) 原文链接:http://www.jianshu.com/p/429b5160611f 著作权归作者所有,转载请联系作者获得授权,并标注"简书作者" ...
- ThreadLocal源码分析:(一)set(T value)方法
在ThreadLocal的get(),set()的时候都会清除线程ThreadLocalMap里所有key为null的value. 而ThreadLocal的remove()方法会先将Entry中对k ...
- JAVA_SE基础——20.数组的常见操作
1.遍历数组 使用for循环来遍历数组 代码如下: public class Ergodic { public static void main(String[] args) { int[] arr ...
- C# 一个初学者对 依赖注入 IOC 的理解( 含 Unity 的使用)
通过 人打电话 来谈谈自己对IOC的理解 版本1.0 public class Person { public AndroidPhone Phone { get; set; } public void ...
- kubernetes入门(09)kubernetes1.7集群安装(2017/11/13)
CentOS7.3利用kubeadm安装kubernetes1.7.3完整版(官方文档填坑篇) https://www.cnblogs.com/liangDream/p/7358847.html 一. ...
- angular2 学习笔记 ( translate, i18n 翻译 )
更新 : 2017-06-17 <h1 i18n="site header|An introduction header for this sample">Hello ...
- 转:java中Vector的使用
转:https://www.cnblogs.com/zhaoyan001/p/6077492.html Vector 可实现自动增长的对象数组. java.util.vector提供了向量类(vect ...
- Python/MySQL(一、基础)
Python/MySQL(一.基础) mysql: MYSQL : 是用于管理文件的一个软件 -socket服务端 (先启动) -本地文件操作 -解析 指令[SQL语句] -客户端软件 (各种各样的客 ...
- poj 2945 Find the Clones
https://vjudge.net/problem/POJ-2945 题意: 给出n个长度相同的DNA序列,如果一个DNA序列出现过两次,那么就有说明它被复制了一次.问被复制0次,1次,2次--n- ...