hihoCoder Challenge 7 register

Ended

Participants:391

Verdict:Accepted
Submitted:2015-01-18 19:45:34

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;
typedef long long LL;
const int N = 100005;
const int Q = 1e9 + 7;
int n , K , f[N] , s[N] , a[N];
pair<int , int> E[N];
int getf(int x) {return f[x] == x ? x : f[x] = getf(f[x]);}
vector<int> e[N];
void work() {
    int i , j , x , y;
    for (i = 1 ; i <= n ; ++ i) {
        scanf("%d" , &a[i]);
        f[i] = i , s[i] = 1;
        e[i].clear();
    }
    for (i = 1 ; i < n ; ++ i) {
        scanf("%d%d",&x,&y);
        E[i] = make_pair(x , y);
        if (a[x] >= K && a[y] >= K) {
            x = getf(x) , y = getf(y);
            if (x != y) {
                f[x] = y;
                s[y] += s[x];
            }
        } else {
            if (a[x] < K && a[y] < K)
                continue;
            if (a[x] < K)
                e[x].push_back(y);
            else
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX