【Codeforces Round #453 (Div. 2) B】Coloring a Tree
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
从根节点开始。
显然它是什么颜色.就要改成对应的颜色。(如果上面已经有某个点传了值就不用改
然后往下传值。
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4;
int n,c[N+10],ans;
vector <int> g[N+10];
void dfs(int x,int C){
int flag = C;
if (C!=c[x]){
ans++;
flag = c[x];
}
for (int i = 0;i < (int) g[x].size();i++){
int y = g[x][i];
dfs(y,flag);
}
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >>n;
for (int i = 2;i <= n;i++){
int fa;
cin >> fa;
g[fa].push_back(i);
}
for (int i = 1;i <= n;i++) cin >> c[i];
dfs(1,0);
cout << ans << endl;
return 0;
}
【Codeforces Round #453 (Div. 2) B】Coloring a Tree的更多相关文章
- 【Codeforces Round #453 (Div. 2) A】 Visiting a Friend
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 维护最右端的端点就好. [代码] #include <bits/stdc++.h> using namespace st ...
- 【Codeforces Round #453 (Div. 2) C】 Hashing Trees
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然只有当a[i]和a[i-1]都大于1的时候才会有不同的情况. a[i] >= a[i-1] 且a[i-1]>=2 则 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- vue5 过滤器 模版
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Gym - 100625J Jailbreak 最短路+搜索
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...
- 【引用】Android程序实现完全退出
这是我在网上找到的,方法不错,都能够实现程序的完全退出http://www.jb51.net/article/37992.htm
- OPENCV(3) —— 对XML和YAML文件实现I/O 操作
XML\YAML文件在OpenCV中的数据结构为FileStorage string filename = "I.xml"; FileStorage fs(filename, Fi ...
- Python正则表达式初识(一)
首先跟大家简单唠叨两句为什么要学习正则表达式,为什么在网络爬虫的时候离不开正则表达式.正则表达式在处理字符串的时候扮演着非常重要的角色,在网络爬虫的时候也十分常用,大家可以把它学的简单一些,但是不能不 ...
- power design设计数据库
power design是收费软件 大致设计流程: 画出概念数据模型,添加实体,连接实体间关系 生成物理数据模型,可以继续在此基础上修改 生成数据库脚本(一个.sql文件),文件中前面是删除表,后面是 ...
- 学习参考《Python数据分析与挖掘实战(张良均等)》中文PDF+源代码
学习Python的主要语法后,想利用python进行数据分析,感觉<Python数据分析与挖掘实战>可以用来学习参考,理论联系实际,能够操作数据进行验证,基础理论的内容对于新手而言还是挺有 ...
- WP8 学习笔记(001_环境配置)
Step 1 WP8 的开发要求64位操作系统,Windows 8及以上版本,需要激活版,建议网上买一个注册码.详见安装双系统. Step 2 安装好系统并已经激活之后,需要安装Windows Ph ...
- 【玲珑杯 round#18 B】图论你先敲完模板
[Link]:http://www.ifrog.cc/acm/problem/1146 [Description] [Solution] 设f[i]表示在第i个点休息的话最少需要的体力值; f[i]= ...
- VIjos——V 1782 借教室 | | 洛谷——P1083 借教室
https://vijos.org/p/1782|| https://www.luogu.org/problem/show?pid=1083 描述 在大学期间,经常需要租借教室.大到院系举办活动,小到 ...