Submission #648207

# Submission time Handle Problem Language Result Execution time Memory
648207 2022-10-05T17:27:43 Z beaconmc Stranded Far From Home (BOI22_island) Python 3
10 / 100
1000 ms 79364 KB
import sys


def find(a):
    while cc[a] != a:
        cc[a] = cc[cc[a]]
        a = cc[a]
    return a


def union(a, b):
    aa = find(a)
    bb = find(b)
    if aa==bb: return

    if siz[aa] < sizes[b]:
        for i in stuff[aa]:
            ans[i] = 0
        stuff[aa] = []

    if siz[bb] < sizes[a]:
        for i in stuff[bb]:
            ans[i] = 0
        stuff[bb] = []

    if len(stuff[aa]) > len(stuff[bb]):
        stuff[aa],stuff[bb] = stuff[bb], stuff[aa]
    
    for i in stuff[aa]:
        stuff[bb].append(i)
        
    siz[bb] += siz[aa]

    
    cc[aa] = bb
    
    



n,m = map(int, input().split())
cc = [i for i in range(n)]
sizes = list(map(int, input().split()))

siz = list(sizes)

stuff = [[i]for i in range(n)]
ans = [1 for i in range(n)]

edges = []
for i in range(m):
    a,b = map(int, input().split())
    a-=1;b-=1
    edges.append([max(sizes[a],sizes[b]),min(sizes[a],sizes[b]), a,b])
edges.sort()

for i in edges:
    union(i[2],i[3])
    
for i in ans:
    print(i, end="")
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2900 KB Output is correct
2 Correct 15 ms 2900 KB Output is correct
3 Correct 13 ms 2896 KB Output is correct
4 Correct 31 ms 3668 KB Output is correct
5 Correct 31 ms 3820 KB Output is correct
6 Correct 29 ms 3720 KB Output is correct
7 Correct 29 ms 3724 KB Output is correct
8 Correct 30 ms 3532 KB Output is correct
9 Correct 30 ms 3796 KB Output is correct
10 Correct 32 ms 3796 KB Output is correct
11 Correct 32 ms 3808 KB Output is correct
12 Correct 35 ms 3764 KB Output is correct
13 Correct 31 ms 3836 KB Output is correct
14 Correct 30 ms 3752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2900 KB Output is correct
2 Correct 14 ms 2900 KB Output is correct
3 Execution timed out 1087 ms 79364 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2960 KB Output is correct
2 Execution timed out 1090 ms 78884 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2900 KB Output is correct
2 Execution timed out 1094 ms 79220 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2900 KB Output is correct
2 Correct 15 ms 2900 KB Output is correct
3 Correct 13 ms 2896 KB Output is correct
4 Correct 31 ms 3668 KB Output is correct
5 Correct 31 ms 3820 KB Output is correct
6 Correct 29 ms 3720 KB Output is correct
7 Correct 29 ms 3724 KB Output is correct
8 Correct 30 ms 3532 KB Output is correct
9 Correct 30 ms 3796 KB Output is correct
10 Correct 32 ms 3796 KB Output is correct
11 Correct 32 ms 3808 KB Output is correct
12 Correct 35 ms 3764 KB Output is correct
13 Correct 31 ms 3836 KB Output is correct
14 Correct 30 ms 3752 KB Output is correct
15 Correct 15 ms 2900 KB Output is correct
16 Correct 14 ms 2900 KB Output is correct
17 Execution timed out 1087 ms 79364 KB Time limit exceeded
18 Halted 0 ms 0 KB -