hiho week 14 register

Ended

Participants:423

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-07 19:23:17

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 <algorithm>
#include <string>
#include <map>
using namespace std;
const int MaxN = 200005;
struct People {
  int _pre;
  int _sum;
  void init (int id) {
      _pre = id;
      _sum = 1;
  }
};
People ps[MaxN];
int cntP;
int find (int x) {
    if (x == ps[x]._pre) return x;
    else return ps[x]._pre = find(ps[x]._pre);
}
void unin (int x, int y) {
    int prex = find(x), prey = find(y);
    if (prex == prey) return;
    if (ps[prex]._sum > ps[prey]._sum) {
        ps[prey]._pre = prex;
        ps[prex]._sum += ps[prey]._sum;
    } else {
        ps[prex]._pre = prey;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX