[Offer收割]编程练习赛25 register

Ended

Participants:399

Verdict:Accepted
Score:100 / 100
Submitted:2017-09-03 13:04:55

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <algorithm>
using namespace std;
 int N;
int numPartition(unordered_map<int, unordered_set<int> > &tree, vector<bool> &visit, unordered_map<int, int> &map_num_node, int cur)
{
    if(visit[cur])  return 0;
    visit[cur] = true;
    for(int next : tree[cur]){
        if(!visit[next])
            map_num_node[cur] += numPartition(tree, visit, map_num_node, next);
    }
    return map_num_node[cur];
}
int main(){
    unordered_map<int, unordered_set<int>> tree;
    unordered_map<int, int> map_num_node;
    int n;
    scanf("%d", &n);
    N = n;
    vector<bool> visit(n + 1, false);
    int a = 0, b = 0;
    for(int i = 0; i < n - 1; i++){
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX