hiho week 268 register

Ended

Participants:66

Verdict:Accepted
Score:100 / 100
Submitted:2019-08-19 22:12:57

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>
using namespace std;
const int MAX_N = 100010;
int parents[MAX_N];
int weights[MAX_N];
int query(int x)
{
    int px = parents[x];
    if (px != x)
    {
        parents[x] = query(px);
        weights[x] += weights[px];
    }
    return parents[x];
}
void join(int a, int b, int w)
{
    // 
    int ga = query(a);
    int gb = query(b);
    if (ga == gb)
        return ;
    parents[ga] = gb;
    weights[ga] = w + weights[b] - weights[a];
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX