Submission #419154


Source Code Expand

import sys
 
def find(x):
    if x == table[x]:
        return x
    else:
        table[x] = find(table[x])
        return table[x]
 
def union(x, y):
    s1 = find(x)
    s2 = find(y)
    if s1 != s2:
        table[s2] = s1
 
N, M = map(int, input().split())
table = [i for i in range(N)]
sys.setrecursionlimit(100001)
for i in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    union(a, b)
 
res = 0
for i in range(N):
    if table[i] == i:
        res += 1
print(res - 1)

Submission Info

Submission Time
Task B - 道路工事
User yumechi
Language Python (3.2.3)
Score 100
Code Size 518 Byte
Status AC
Exec Time 1412 ms
Memory 12584 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 20
Set Name Test Cases
Sample sample1.txt, sample2.txt
All 0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt
Case Name Status Exec Time Memory
0.txt AC 131 ms 8500 KB
1.txt AC 128 ms 8500 KB
10.txt AC 128 ms 8628 KB
11.txt AC 128 ms 8500 KB
12.txt AC 128 ms 8500 KB
13.txt AC 130 ms 8464 KB
14.txt AC 128 ms 8500 KB
15.txt AC 1284 ms 8496 KB
16.txt AC 198 ms 12584 KB
17.txt AC 193 ms 12456 KB
18.txt AC 194 ms 12584 KB
19.txt AC 1412 ms 12584 KB
2.txt AC 128 ms 8628 KB
3.txt AC 128 ms 8628 KB
4.txt AC 128 ms 8628 KB
5.txt AC 127 ms 8500 KB
6.txt AC 129 ms 8468 KB
7.txt AC 127 ms 8500 KB
8.txt AC 126 ms 8500 KB
9.txt AC 127 ms 8628 KB
sample1.txt AC 127 ms 8500 KB
sample2.txt AC 127 ms 8500 KB