题目链接

题目大意

给你一颗树,Alice在a点,Bob在b点,Alice最多走da步,Bob最多走db步,两人轮流走路。要你判断经过无数次追赶后,Alice是否可以追上Bob,两人进行的都是最优策略

题目思路

感觉也不特别像一个博弈,但是也不知道该划分到哪里了

这个题目没想象的那么难,首先如果a和b的距离小于da,那么肯定Alice胜,如果2da>=len,len代表树的直径,那么也是Alice胜。 前两个都是显然的。 还有一种如果2*da>=db,这个代表不存在A只差一步追上B的时候,B可以反向再跑一段很长的距离,使得A一步追不上B。那么也是Alice胜

代码

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define fi first
#define se second
#define debug printf(" I am here\n");
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e5+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-10;
int n,a,b,da,db,dis[maxn];
int head[maxn],cnt;
struct node{
int to,next;
}e[maxn<<1];
void add(int u,int v){
e[++cnt]={v,head[u]};
head[u]=cnt;
}
void dfs(int son,int fa){
int cur=0;
for(int i=head[son];i;i=e[i].next){
if(e[i].to==fa) continue;
dis[e[i].to]=dis[son]+1;
dfs(e[i].to,son);
}
}
void init(){
cnt=0;
for(int i=1;i<=n;i++){
head[i]=dis[i]=0;
}
}
signed main(){
int _; scanf("%d", &_);
while(_--){
scanf("%d%d%d%d%d",&n,&a,&b,&da,&db);
init();
for(int i=1,u,v;i<=n-1;i++){
scanf("%d%d",&u,&v);
add(u,v),add(v,u);
}
dfs(a,-1);
bool flag=0;
if(da>=dis[b]){//第一次直接抓住Bob
flag=1;
}
int ma=0,v;
for(int i=1;i<=n;i++){//寻找最远的端点
if(dis[i]>ma){
ma=dis[i];
v=i;
}
}
for(int i=1;i<=n;i++){
dis[i]=0;
}
dfs(v,-1);
int len=0;
for(int i=1;i<=n;i++){
len=max(len,dis[i]);
//树的直径
}
if(2*da>=len||2*da>=db){
flag=1;
}
puts(flag?"Alice":"Bob");
}
return 0;
}

Codeforces Round #668 (Div. 2) D. Tree Tag 题解(博弈)的更多相关文章

  1. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  2. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  3. Codeforces Round #668 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1405 A. Permutation Forgery 题意 给出一个大小为 $n$ 的排列 $p$,定义 \begin{equ ...

  4. Codeforces Round #353 (Div. 2) D. Tree Construction 二叉搜索树

    题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: ...

  5. Codeforces Round #540 (Div. 3)--1118F1 - Tree Cutting (Easy Version)

    https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; in ...

  6. Codeforces Round #353 (Div. 2) D. Tree Construction 模拟

    D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the pr ...

  7. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  8. Codeforces Round #527 (Div. 3) F. Tree with Maximum Cost 【DFS换根 || 树形dp】

    传送门:http://codeforces.com/contest/1092/problem/F F. Tree with Maximum Cost time limit per test 2 sec ...

  9. 数据结构 - Codeforces Round #353 (Div. 2) D. Tree Construction

    Tree Construction Problem's Link ------------------------------------------------------------------- ...

随机推荐

  1. STM32入门系列-STM32时钟系统,STM32时钟树

    时钟对于单片机来说是非常重要的,它为单片机工作提供一个稳定的机器周期从而使系统能够正常运行.时钟系统犹如人的心脏,一旦有问题整个系统就崩溃.我们知道STM32属于高级单片机,其内部有很多的外设,但不是 ...

  2. configfs_sample.c 理解

    1. 编译运行 代码从如下链接获得: https://github.com/torvalds/linux/blob/master/samples/configfs/configfs_sample.c ...

  3. 公钥、私钥、SSL/TLS、会话密钥、DES

    一,公钥私钥 1,公钥和私钥成对出现 2,公开的密钥叫公钥,只有自己知道的叫私钥 3,用公钥加密的数据只有对应的私钥可以解密 4,用私钥加密的数据只有对应的公钥可以解密 5,如果可以用公钥解密,则必然 ...

  4. yum安装出现被锁定的报错

    问题:在使用#yum install XXX 命令的时候,出现yum.pid 已被锁定的提示,无法进行yum 安装 解决: 使用# rm -f /var/run/yum.pid  命令删除该进程即可

  5. JIRA、Confluence等产品明年2月停售本地化版本,将影响中国近90%的客户!

    作为目前应用最为广泛的软件开发管理软件,JIRA.Confluence等产品几乎被所有的科技型公司所应用.我们的每天的任务管理.文档编写等工作几乎都在这些软件的帮助下进行和管理.当然我也不例外,在读书 ...

  6. BIM+GIS它们各有什么优缺点

    BIM+GIS它们各有什么优缺点?应用有哪些优势?BIM模型精细程度高,语义信息丰富,侧重整合和管理建筑物自身所有阶段信息,包括建筑物所有微观图形化和非图形化信息,三维GIS侧重宏观.大范围地理环境与 ...

  7. iptables-centos|mysql navicat登陆不上

    iptables-centos: vi /etc/sysconfig/iptables service iptables restart ====================== mysql na ...

  8. strace 使用文档

    strace -c 统计每一系统调用的所执行的时间,次数和出错的次数等. -d 输出strace关于标准错误的调试信息. -f 跟踪由fork调用所产生的子进程. -ff 如果提供-o filenam ...

  9. win7-64位 jdk安装

    1.jdk安装 jdk安装主要是进行jdk以及jre安装,注意jre需要安装到一个空文件夹内即可. 官网地址:http://www.oracle.com/technetwork/java/javase ...

  10. Ubuntu 12.10设置root用户登录图形界面

    Ubuntu 12.04默认是不允许root登录的,在登录窗口只能看到普通用户和访客登录.以普通身份登陆Ubuntu后我们需要做一些修改,普通用户登录后,修改系统配置文件需要切换到超级用户模式,在终端 ...