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

Ended

Participants:399

Verdict:Accepted
Score:100 / 100
Submitted:2017-09-03 12:23:35

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 <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
vector<int>v[maxn];
int num[maxn];
int N;
void dfs(int st,int fa)
{
    num[st]=1;
    for(int i=0;i<v[st].size();i++)
    {
        int u=v[st][i];
        if(u==fa) continue;
        else
            dfs(u,st);
        num[st]+=num[u];
    }
}
int main()
{
    while(scanf("%d",&N)!=EOF)
    {
        memset(num,0,sizeof(num));
        for(int i=1;i<=N;i++)
            v[i].clear();
        for(int i=1;i<N;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            v[a].push_back(b);
            v[b].push_back(a);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX