2018HDU多校训练-3-Problem F. Grab The Tree
In this game, Little Q needs to grab some vertices on the tree. He can select any number of vertices to grab, but he is not allowed to grab both vertices that are adjacent on the tree. That is, if there is an edge between x
and y
, he can't grab both x
and y
. After Q's move, Little T will grab all of the rest vertices. So when the game finishes, every vertex will be occupied by either Q or T.
The final score of each player is the bitwise XOR sum of his choosen vertices' value. The one who has the higher score will win the game. It is also possible for the game to end in a draw. Assume they all will play optimally, please write a program to predict the result.
, denoting the number of test cases.
In each test case, there is one integer n(1≤n≤100000)
in the first line, denoting the number of vertices.
In the next line, there are n
integers w1
,w
2
,...,w
n
(1≤w
i
≤10
9
)
, denoting the value of each vertex.
For the next n−1
lines, each line contains two integers u
and v
, denoting a bidirectional edge between vertex u
and v
.
3
2 2 2
1 2
1 3
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int w[maxn],u[maxn],v[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); int T,n;
cin>>T;
while(T--)
{
cin>>n;
bool flag=false;
for(int i=1;i<=n;i++) cin>>w[i];
for(int i=1;i<n;i++) cin>>u[i]>>v[i];
for(int i=0;i<32;i++)
{
int cnt=0;
for(int i=1;i<=n;i++)
{
if(w[i]&1) cnt++;
w[i]>>=1;
}
if(cnt & 1)
{
cout<<"Q"<<endl;
flag=true;
break;
}
}
if(!flag) cout<<"D"<<endl;
} return 0;
}
2018HDU多校训练-3-Problem F. Grab The Tree的更多相关文章
- 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...
- Problem F. Grab The Tree HDU - 6324
题意:给出一棵n个节点的树,每个节点有一个权值,Q和T玩游戏,Q先选一些不相邻的节点,T选剩下的节点,每个人的分数是所选节点的权值的异或和,权值大的胜出,问胜出的是谁. 题解: 话说,这题后面的边跟解 ...
- HDU 6324.Problem F. Grab The Tree-博弈(思维) (2018 Multi-University Training Contest 3 1006)
6324.Problem F. Grab The Tree 题目看着好难,但是题解说的很简单,写出来也很简单.能想出来就是简单的,想不出来就难(讲道理,就算是1+1的题目,看不出来就是难的啊). 和后 ...
- 2018HDU多校训练-3-Problem D. Euler Function
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...
- 牛客网多校训练第一场 F - Sum of Maximum(容斥原理 + 拉格朗日插值法)
链接: https://www.nowcoder.com/acm/contest/139/F 题意: 分析: 转载自:http://tokitsukaze.live/2018/07/19/2018ni ...
- 2018HDU多校训练-3-Problem M. Walking Plan
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6331 Walking Plan Problem Description There are n inte ...
- 2018HDU多校训练-3-Problem G. Interstellar Travel
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6325 Interstellar Tra ...
- 2018HDU多校训练一 K - Time Zone
Chiaki often participates in international competitive programming contests. The time zone becomes a ...
- 2018HDU多校训练一 D Distinct Values
hiaki has an array of nn positive integers. You are told some facts about the array: for every two e ...
随机推荐
- F#周报2019年第46期
新闻 使用Pulumi和.NET Core创建现代云应用 宣告.NET Core 3.1预览版3 ML.NET模型构建器升级 .NET Framework修复工具 Mac上的Visual Studio ...
- 创建基于OData的Web API - Knowledge Builder API, Part III:Write Model
在前两篇文章<Part I: Business Scenario> 和<Part II: Project Setup>后,可以开始真正Model的创建. 步骤如下: 1. 创建 ...
- 微信小程序引入全局或公共样式
在开发的过程中,总会遇到很多可复用性的样式,为了代码更加的简洁和减少微不住道的文件体积,我抽取了一部分的公共样式,并全局引入,不知是否妥当,如有更好的想法,欢迎一起探讨 在app.wxss中引入 然后 ...
- nyoj 96-n-1位数 (strlen, atoi, ceil)
96-n-1位数 内存限制:64MB 时间限制:3000ms 特判: No 通过数:30 提交数:47 难度:1 题目描述: 已知w是一个大于10但不大于1000000的无符号整数,若w是n(n≥2) ...
- 关于 Python 对象拷贝的那点事?
概述 在本篇文章中,会先介绍 Python 中对象的基础概念,之后会提到对象的深浅拷贝以及区别.在阅读后,应该掌握如下的内容: 理解变量.引用和对象的关系 理解 Python 对象中 identity ...
- 【2018寒假集训 Day2】【动态规划】又上锁妖塔
又上锁妖塔 (tower.in/tower.out) [题目描述] 小D在X星买完了想要的东西,在飞往下一个目的地的途中,正无聊的他转头看了看身边的小A,发现小A正在玩<仙剑>,可是小A很 ...
- linux 进程简介
进程相关知识简介 进程定义: 一个运行中的程序即一个process task struct: 内核存储进程信息的固定格式称为task struct,task struct记录了例如该进程内存下一跳位置 ...
- day 19 os模块的补充 序列化 json pickle
os 模块 os.path.abspath 规范绝对路径 os.path.split() 把路径分成两段,第二段是一个文件或者是文件夹 os.path.dirname 取第一部分 os.p ...
- ctf线下赛中检测外来IP的shell脚本
该脚本可用于ctf线下赛中,用来检测攻击IP的接入,及时做出响应. #!/bin/bash #写自己队的ip ipA="172.22.60.230" ipB="172.2 ...
- JSONPath小试牛刀之Snack3
最近在网上看了些JSONPath的入门例子.打算用Snack3这个框架写写例子.json path对`JSON的处理绝对是神器. 1.准备JSON字符串 { "store": { ...