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 ...
随机推荐
- 浅谈配置文件:spring-servlet.xml(spring-mvc.xml) 与 applicationContext.xml
在搭建 spring mvc 的框架时,会有2个配置文件必不可少: spring-servlet.xml 和applicationContext.xml.第一次接触spring mvc的工程师可能会对 ...
- vim搜索设置高亮
vim搜索设置高亮 linux vim打开文档搜索字符串时,设置被搜索到字符串高亮显示. 有两种方法: 1.暂时设置:vim打开文档-->命令行形式输入set hlsearch. 缺点:关闭文档 ...
- vim 设置
TL;DR: $ git clone https://github.com/sontek/dotfiles.git $ cd dotfiles $ ./install.sh vim Download ...
- 在CentOS 7上利用systemctl添加自定义系统服务 /usr/lib/systemd/
在CentOS 7上利用systemctl添加自定义系统服务[日期:2014-07-21] 来源:blog.csdn.net/yuanguozhengjust 作者:yuanguozhengjust ...
- 运动规划(Motion Planning)
相关介绍: https://mp.weixin.qq.com/s?__biz=MzA5MDE2MjQ0OQ==&mid=2652786406&idx=1&sn=f937dd6a ...
- 第二百二十三节,jQuery EasyUI,ComboBox(下拉列表框)组件
jQuery EasyUI,ComboBox(下拉列表框)组件,可以远程加载数据的下拉列表组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 C ...
- db2 clob dbclob
DB2有三种类型的大字段: clob(Character Large OBjects ) 适用于存放单字节的字符串,当我们要保存的字符长度超过varchar的最大长度(32K)时,我们就要考虑使用cl ...
- Ajax实现验证码异步校验
验证码异步校验可以防止表单提交后因验证码不正确导致已填的其它项都清空. 整个过程图如下 验证码输入框出代码 <div class="form-group"> <l ...
- 面试STAR法则
昨天投了几家公司的简历,A公司还没看简历,B公司没有通过简历,另外的后说(其实只投了这两家),B公司最终给了蛮中肯的回复: 虽然,一开始看到这样的结果,有些失落,仔细看过回复后,有些不屑和好奇.百度了 ...
- vue+node+mongoDB 火车票H5(四)---完成静态页面
各项配置都好了,就可以开始写静态页面了,先别急着写,看一下页面又哪些公用的部分可以提取出来的,统一放到components组件文件夹中 header头部文件夹放一些头部常用组件,如首页的banner切 ...