Codeforces Round 245 div1A&div2C Xor-tree dfs暴搜
来源:互联网 发布:linux c vim 编辑:程序博客网 时间:2024/06/07 02:31
题目链接点这儿
给一颗树,1为根,每次可以选一张牌执行一次翻转操作,除了自身外,自己的孙子(嘛,就是儿子的儿子啦),孙子的孙子都会翻转。问最少多少次翻转可以把题中给出的原始状态变成要的理想状态。
这题意,dfs肯定dfs啦因为翻转不会改变父亲们的状态,所以只要一点一点的向下dfs就好啦。没什么蛋疼的地方╮( ̄▽ ̄")╭
下面是代码
#include <bits/stdc++.h>#define max(a,b) ((a)>(b)?(a):(b))#define min(a,b) ((a)>(b)?(b):(a))#define rep(i,initial_n,end_n) for(int (i)=(initial_n);(i)<(end_n);i++)#define repp(i,initial_n,end_n) for(int (i)=(initial_n);(i)<=(end_n);(i)++)#define reep(i,initial_n,end_n) for((i)=(initial_n);(i)<(end_n);i++)#define reepp(i,initial_n,end_n) for((i)=(initial_n);(i)<=(end_n);(i)++)#define eps 1.0e-9using namespace std;typedef pair<int, int> pii;typedef pair<double, double> pdd;typedef __int64 ll;typedef unsigned __int64 ull;const double pi = acos(-1);int getint(){ int x=0,tmp=1; char c=getchar(); while((c<'0'||c>'9')&&c!='-') c=getchar(); if(c == '-') c=getchar() , tmp = -1; while(c>='0'&&c<='9') x*=10,x+=(c-'0'),c=getchar(); return x*tmp;}vector<int> v[100010], ans;int init[100010], need[100010], a[2] = { 0 };//void dfs(int now, int time, int a[]);void dfs(int now, int fa, int toplus, int next);int main() { int n, tmp, tmpp; n = getint(); rep(i, 0, n-1) { tmp = getint(), tmpp = getint(); v[tmp].push_back(tmpp); v[tmpp].push_back(tmp); } repp(i, 1, n) init[i] = getint(); repp(i, 1, n) need[i] = getint(); //dfs(1, 0, a); dfs(1, 0, 0, 0); sort(ans.begin(), ans.end()); printf("%d\n", ans.size()); rep(i, 0, ans.size()) printf("%d\n", ans[i]); return 0;}void dfs(int now, int fa, int toplus, int next) { if((init[now] ^ need[now]) != toplus) { toplus ^= 1; ans.push_back(now); } int len = v[now].size(); rep(i, 0, len) if(v[now][i] != fa) dfs(v[now][i], now, next, toplus);}
0 0
- Codeforces Round 245 div1A&div2C Xor-tree dfs暴搜
- CodeForces 498A Round #284 div1A(div2C) Crazy Town
- CodeForces Round #423 Div2C&Div1A(827A) Solution
- Codeforces Round #245 (Div. 2) C. Xor-tree DFS
- Codeforces Round242 div1A&div2C Magic Formulas
- Codeforces Round #250 Div1A Div2C 437C The Child and Toy 贪心
- Codeforces 853A Round#433 Div2C & Div1A Planning:优先队列或堆或排序
- Codeforces #245 (Div. 2)C. Xor-tree(DFS&&贪心
- Codeforces Round #245 (Div. 1)——Xor-tree
- Codeforces Round #245 (Div. 2)-C. Xor-tree
- CodeForces 430C Xor-tree(DFS)
- Codeforces 430C Xor-tree【Dfs+思维】
- Codeforces 430C Xor-Tree DFS,奇偶性
- [贪心+dfs] Codeforces 429A A. Xor-tree
- Codeforces Round #245 (Div. 1) A /(Div.2 C) Xor-tree
- [Codeforces Round #286 DIV1A (CF506A)] Mr. Kitayuta, the Treasure Hunter
- [Codeforces Round #310 DIV1A (CF555A)] Case of Matryoshkas
- [Codeforces Round #372 DIV1A (CF715A)] Plus and Square Root
- 传统IT列强和互联网新贵们如何应对大数据浪潮
- visual studio2008 下,用vc++开发activex控件
- C++ GUI QT 第4版 之线程(一) 线程的创建
- 初学S2SH的整合:(没使用事务控制)
- C++ GUI QT 第4版 之线程(二) 线程的同步(1)
- Codeforces Round 245 div1A&div2C Xor-tree dfs暴搜
- 读写配置文件的一些说明
- 如何在MFC中创建和使用对话框
- python for 中的range
- js中的doucment.body和document.documentElement
- JS兼容方式获取浏览器的宽度
- "调试“:如何使梯度下降正常工作
- sublime text 2 安装Package Control
- 黑马程序员_Java面对对象——异常