Codeforces 930 A. Peculiar apple-tree (dfs)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 930 A. Peculiar apple-tree (dfs)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目:
代碼:
#include <bits\stdc++.h> using namespace std;int b[100010]; //b[i]表示距離1號(hào)花絮i步的花絮的個(gè)數(shù) map <int, list <int> > m; //m[i]表示第i個(gè)花絮連接的花絮標(biāo)號(hào) int ans = 0;void dfs(int con, int step){b[step]++;for(list <int>::iterator it = m[con].begin();it != m[con].end(); it++){dfs(*it, step+1);}}int main(){int n, key;cin >> n;for(int i = 2;i <= n; i++){cin >> key;m[key].push_back(i);}dfs(1, 0);for(int i = 0;i < 100010; i++){ans += b[i]%2;}cout << ans << endl;return 0; }總結(jié)
以上是生活随笔為你收集整理的Codeforces 930 A. Peculiar apple-tree (dfs)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51nod 2020 排序相减(暴力解法
- 下一篇: Codeforces 959 E. Ma