hiho week 183 register

Ended

Participants:162

Verdict:Accepted
Score:100 / 100
Submitted:2018-01-03 19:30:13

Lang:Python2

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
N = 1000
d = (-10100-101)
res = 0
n = int(raw_input())
fa = [i for i in xrange(N * N + 1)]
mark = [0] * (N * N + 1)
def findFa(x):
    s = []
    s.append(x)
    while s[-1] != fa[s[-1]]s.append(fa[s[-1]])
    f = s[-1]
    for x in sfa[x] = f
    return f
while n:
    xy = map(intraw_input().split())
    u = x * N + y
    res += 1
    mark[u] = 1
    for i in xrange(4):
        xx = x + d[i * 2]
        yy = y + d[i * 2 + 1]
        if xx >= 0 and xx < N and yy >= 0 and yy < N:
            v = findFa(xx * N + yy)
            u = findFa(u)
            if mark[v] and u != v:
                fa[v] = u
                res -= 1
    print res
    n -= 1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX