hiho week 245 register

Ended

Participants:153

Verdict:Accepted
Score:100 / 100
Submitted:2019-03-11 20:47:08

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>
#define M 1001005
using namespace std;
const int rx[]= {1,0,-1,0};
const int ry[]= {0,1,0,-1};
int f[M];
bool mark[M];
int getfa(int x){
    return  f[x]==x?x:f[x]=getfa(f[x]);
}
int main() {
    for(int i=0;i<1000;i++)
        for(int j=0;j<1000;j++)
            f[i+j*1000]=i+j*1000;
    int n,C=0,island=0;
    scanf("%d",&n);
    for(int I=1; I<=n; I++) {
        int x,y,cnt=0;
        scanf("%d%d",&x,&y);
        island++;
        int X=x+y*1000;
        mark[X]=1;
        for(int i=0;i<4;i++){
            int xx=x+rx[i];
            int yy=y+ry[i];
            if(xx<0||xx>=1000||yy<0||yy>=1000)continue;
            int XX=xx+yy*1000;
            if(!mark[XX])continue;
            cnt++;
            int a=getfa(f[X]),b=getfa(f[XX]);
            if(a!=b){
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX