Codeforces 931D Peculiar Apple-tree (dfs+ thinking). cpp

Source: Internet
Author: User

Title Link: Http://codeforces.com/contest/931/problem/D

The main topic: give you a tree, each node will grow apples, and then every second, apple roll down one. Two of the two will counteract the apples. Ask how many apples can be received at the root node at the end.

Problem-solving ideas: Yesterday is I want to complicate, in fact, the statistics of each layer of the number of apples, if the odd answer +1. Because eventually these apples will tumble and converge to the root node, so in the rolling process will definitely collide and eliminate no matter how the apple is distributed.

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <vector>5#include <algorithm>6 using namespacestd;7 Const intn=1e5+5;8 9 intDep_num[n];Tenvector<int>V[n]; One  A voidDfsintUintDEP) { -dep_num[dep]++; -      for(intI=0; I<v[u].size (); i++){ the         intt=V[u][i]; -DFS (t,dep+1); -     } - } +  - intMain () { +     intN; Ascanf"%d",&n); at      for(intI=2; i<=n;i++){ -         intFA; -scanf"%d",&FA); - V[fa].push_back (i); -     } -Dfs1,1); in     intans=0; -      for(intI=0; i<n;i++){ toans+=dep_num[i]%2; +     } -printf"%d\n", ans); the     return 0; *}

Codeforces 931D Peculiar Apple-tree (dfs+ thinking). cpp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.