【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个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- WebForms简介
http://www.w3school.com.cn/aspnet/aspnet_intro.asp ASP.NET 是下一代 ASP,不是 ASP 的更新版本. https://docs.micro ...
- linux log日志解析
linux log日志解析 其实,可以说成是监控系统的记录,系统一举一动基本会记录下来.这样由于信息非常全面很重要,通常只有 root 可以进行视察!通过登录文件(日志文件)可以根据屏幕上面的错误 ...
- Android自定义组件系列【14】——Android5.0按钮波纹效果实现
今天任老师发表了一篇关于Android5.0中按钮按下的波纹效果实现<Android L中水波纹点击效果的实现>,出于好奇我下载了源代码看了一下效果,正好手边有一个Nexus手机,我结合实 ...
- Linux软件万花筒
650) this.width=650;" border="0" alt="" src="http://img1.51cto.com/att ...
- C# 利用反射和特性 来做一些事情
特性代码: [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] public clas ...
- hight charts
hight charts http://www.hcharts.cn/resource/index.php http://www.hcharts.cn/api/index.php
- BZOJ 4430 Guessing Camels
Description Jaap, Jan, and Thijs are on a trip to the desert after having attended the ACM ICPC Worl ...
- JavaScript笔记(6)
一.Date Date实例用来处理日期和时间.Date对象基于1970年1月1日(格林威治时间)世界标准时间起经过的毫秒数.常用:new Date();new Date(value);new Date ...
- U-BOOT启动流程分析--start_armboot函数(二)
第二阶段的功能: 初始化本阶段所需的硬件设备(主要设置系统时钟.初始化串口.Flash.网卡.USB) 检测系统内存映射(memory map) 将内核映像和根文件系统映象从Flash上读到RAM空间 ...
- CMDB学习之七-实现采集错误捕捉,日志信息处理
首先采集disk的具体实现方上代码: # !/usr/bin/env python # -*- coding:utf-8 -*- from .base import BasePlugin import ...