Codeforces Round #245 (Div. 1)——Xor-tree
https://blog.csdn.net/u012476429/article/details/25607945
- 题意:
给一棵树n个节点,1为根节点。操作为,选定一个节点x。当前值取反,x的孙子,孙子的孙子。。。
均取反
如今告诉初始时每一个点的值和最后每一个点的目标值。求操作次数最少时须要选择那些节点
(1 ≤ n ≤ 105) - 分析:
深度浅的点一定是受影响最小的(根节点仅仅受自己的影响)。所以从根依次向下递推处理就可以
const int MAXN = 110000;
VI G[MAXN], ans;
int now[MAXN], goal[MAXN];
void dfs(int u, int fa, int a, int b)
{
int rev = ((now[u] ^ a) != goal[u]);
if (rev)
{
ans.push_back(u);
a ^= 1;
}
REP(i, G[u].size())
{
int v = G[u][i];
if (v != fa)
dfs(v, u, b, a);
}
}
int main()
{
// freopen("in.txt", "r", stdin);
int n, a, b;
while (~RI(n))
{
FE(i, 0, n) G[i].clear();
ans.clear();
REP(i, n - 1)
{
RII(a, b);
G[a].push_back(b);
G[b].push_back(a);
}
FE(i, 1, n) RI(now[i]);
FE(i, 1, n) RI(goal[i]);
dfs(1, 0, 0, 0);
WI(ans.size());
REP(i, ans.size())
WI(ans[i]);
}
return 0;
}
Codeforces Round #245 (Div. 1)——Xor-tree的更多相关文章
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #245 (Div. 1)——Guess the Tree
题目链接 题意: n个节点,给定每一个节点的子树(包含自己)的节点个数.每一个节点假设有子节点必定大于等于2.求这种数是否存在 n (1 ≤ n ≤ 24). 分析: 用类似DP的思路,从已知開始.这 ...
- Codeforces Round #353 (Div. 2) D. Tree Construction 二叉搜索树
题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: ...
- 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 ...
- Codeforces Round #353 (Div. 2) D. Tree Construction 模拟
D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the pr ...
- Codeforces Round #245 (Div. 2) C. Xor-tree DFS
C. Xor-tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem/C ...
- 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 ...
- 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 ...
- 数据结构 - Codeforces Round #353 (Div. 2) D. Tree Construction
Tree Construction Problem's Link ------------------------------------------------------------------- ...
- Codeforces Round #316 (Div. 2) D. Tree Requests dfs序
D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
随机推荐
- java中for循环执行过程
for (int j = 0; j < newSize; j++) { //执行todo } 1.首先变量j初始化为0 2.然后j=0的值跟newSize进行比较,假如为true,则执行{}里面 ...
- Iptables详解+实例
Iptabels是与Linux内核集成的包过滤防火墙系统,几乎所有的linux发行版本都会包含Iptables的功能.如果 Linux 系统连接到因特网或 LAN.服务器或连接 LAN 和因特网的代理 ...
- linux split
说来惭愧,用了这么久linux会的命令也只有常用的那么几个.. 今天刚刚学到的一个很实用的split命令,原本就只是知道开发语言中有split方法用来切分字符串,linux命令行也提供了这样一个方法. ...
- 列出自己常用的jdk中的数据结构
列出自己常用的jdk中的数据结构 解答:线性表,链表,哈希表是常用的数据结构.
- Java容器:HashMap和HashSet解析
转载请注明出处:jiq•钦's technical Blog 一.HashMap HashMap,基于散列(哈希表)存储"Key-Value"对象引用的数据结构. 存入的键必须具备 ...
- iOS项目开发实战——自己定义圆形进度提示控件
iOS中默认的进度条是水平方向的进度条,这往往不能满足我们的需求. 可是我们能够自己定义类似的圆形的进度提示控件,主要使用iOS中的画图机制来实现. 这里我们要实现一个通过button点击然后圆形进度 ...
- Windows防火墙端口规则设置新建方法
from:https://jingyan.baidu.com/article/2a1383289fd094074a134ff0.html Windows防火墙有什么用呢?它是电脑的一道安全屏障,可以有 ...
- IOS开发之自定义键盘
本文转载至 http://blog.csdn.net/majiakun1/article/details/41242069 实际开发过程中,会有自定义键盘的需求,比如,需要添加一个表情键盘.本文提供 ...
- boost::interprocess::managed_shared_memory(2)(std::deque)
struct shareDataEx : shareData { int index; int total_size; }; typedef managed_shared_memory::segmen ...
- android应用安全——代码安全(android代码混淆)
android2.3的SDK开始在eclipse中支持代码混淆功能(理论上java都支持混淆,但关键在于如何编写proguard的混淆脚本,2.3的SDK使用简单的配置就可以实现混淆).使用SDK2. ...