Codeforces Round #453 (Div. 2) B
来源:互联网 发布:windows xp翻墙 编辑:程序博客网 时间:2024/06/07 07:40
遍历树
#include<iostream>#include<algorithm>#include<iomanip>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<set>#include<queue>#include<stack>#include<map>#define PI acos(-1.0)#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)#define kuaidian ios::sync_with_stdio(0);using namespace std;typedef long long ll;typedef unsigned long long ull;const int maxn = 1e4 + 7, maxd = 1e8;const ll mod = 1e9 + 7;const int INF = 0x7f7f7f7f;int n, ans = 0, ff = 0;vector<int> vec[maxn];int a[maxn];int b[maxn] = {0};void dfs(int id, int f) { if(a[id] != f) { ans++; } for(int i = 0; i < vec[id].size(); ++i) { dfs(vec[id][i], a[id]); }}int main() { kuaidian; cin >> n; for(int i = 2; i <= n; ++i) { int x; cin >> x; vec[x].push_back(i); } for(int i = 1; i <= n; ++i) { cin >> a[i]; } ans = 0; dfs(1, 0); cout << ans << endl; return 0;}
阅读全文
1 0
- Codeforces Round #453 (Div. 2) A,B
- Codeforces Round #453 (Div. 2) B
- Codeforces Round #453 (Div. 2) B. Coloring a Tree
- Codeforces Round #453 (Div. 2)A,B,C
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- Codeforces Round #206 (Div. 2) - b
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #203 (Div. 2)B
- SpringBoot Beans管理和自动配置 火推 02
- Android Transition(Android过渡动画)
- Mybatis-Generator配置使用方法
- R中的字符处理函数汇总
- 微信开发篇章1 授权
- Codeforces Round #453 (Div. 2) B
- Oracle(一)下
- 爬取简书标题和摘要
- ACE_Service_Handler类的理解和使用
- Ubuntu 16.04 安装 PyCharm
- 在mysql中使用去重distinct需要注意的
- ServerSocket用法
- The record for a starter making a printed circuit board.
- 微服务:微服务架构模式译文说明