MSBOP 2015 Round3 register

Ended

Participants:978

Verdict:AC | AC
Submitted:2015-05-09 16:42:00

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<cstring>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
const int MAXN=1e5+5;
vector<int> g[MAXN];
int n, s;
LL w[MAXN], dp[MAXN];
LL dfs(int x, int fa){
    int sz=g[x].size();
    for(int i=0, idx; i<sz; i++){
        idx=g[x][i];
        if(idx==fa) continue;
        dfs(idx,x);
        w[x]+=w[idx];
    }
    return w[x];
}
int main(){
    int T;
    scanf("%d",&T);
    for(int cs=1; cs<=T; cs++){
        for(int i=1; i<=n; i++){
            g[i].clear();
        }
        scanf("%d%d",&n,&s);
        for(int i=0, x, y; i<n-1; i++){
            scanf("%d%d",&x,&y);
            g[x].push_back(y);
            g[y].push_back(x);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX