hiho week 183 register

Ended

Participants:162

Verdict:Accepted
Score:100 / 100
Submitted:2018-01-06 18:29:30

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
r = range(10**6)
def f(x):
    global r
    if r[x] == x:
        return x
    r[x] = f(r[x])
    return r[x]
v = [False for i in r]
ret = 0
for i in xrange(input()):
    xy = map(intraw_input().split())
    u = x * 1000 + y
    if v[u]:
        continue
    v[u] = True
    ret += 1
    s = set()
    for dxdy in [(10)(-10)(01)(0-1)]:
        xx = x + dx
        yy = y + dy
        if xx < 0 or xx >= 1000 or yy < 0 or yy >= 1000:
            continue
        w = xx * 1000 + yy
        if not v[w]:
            continue
        W = f(w)
        s.add(W)
    ret -= len(s)
    for W in s:
        r[W] = u
    print ret
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX