Submission #648200

# Submission time Handle Problem Language Result Execution time Memory
648200 2022-10-05T17:02:31 Z beaconmc Stranded Far From Home (BOI22_island) PyPy 3
0 / 100
1000 ms 77696 KB
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[bb]:
        for i in stuff[aa]:
            ans[i] = 0
        stuff[aa] = []

    if siz[bb] < sizes[aa]:
        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]), a,b])
edges.sort()

for i in edges:
    union(i[1],i[2])
    
print("".join(map(str, ans)))
# Verdict Execution time Memory Grader output
1 Correct 46 ms 18236 KB Output is correct
2 Correct 36 ms 18180 KB Output is correct
3 Correct 34 ms 18208 KB Output is correct
4 Incorrect 133 ms 26744 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 18144 KB Output is correct
2 Correct 36 ms 18188 KB Output is correct
3 Execution timed out 1065 ms 77696 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 18240 KB Output is correct
2 Execution timed out 1070 ms 76784 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 18220 KB Output is correct
2 Execution timed out 1043 ms 77028 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 18236 KB Output is correct
2 Correct 36 ms 18180 KB Output is correct
3 Correct 34 ms 18208 KB Output is correct
4 Incorrect 133 ms 26744 KB Output isn't correct
5 Halted 0 ms 0 KB -