Submission #2791414
Source Code Expand
n, m = map(int, input().split()) ps = [int(x) for x in input().split()] xs = [tuple(map(int, input().split())) for _ in range(m)] union = {x:x for x in range(1, n+1)} def root(n): if union[n] == n: return n union[n] = root(union[n]) return union[n] for x,y in xs: union[root(x)] = root(y) print(sum(root(i+1) == root(ps[i]) for i in range(n)))
Submission Info
Submission Time | |
---|---|
Task | D - Equals |
User | zehnpaard |
Language | Python (3.4.3) |
Score | 400 |
Code Size | 384 Byte |
Status | AC |
Exec Time | 666 ms |
Memory | 33992 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 17 ms | 3064 KB |
0_001.txt | AC | 17 ms | 3064 KB |
0_002.txt | AC | 17 ms | 3064 KB |
0_003.txt | AC | 17 ms | 3064 KB |
1_004.txt | AC | 390 ms | 12876 KB |
1_005.txt | AC | 503 ms | 33976 KB |
1_006.txt | AC | 596 ms | 33904 KB |
1_007.txt | AC | 17 ms | 3064 KB |
1_008.txt | AC | 17 ms | 3064 KB |
1_009.txt | AC | 17 ms | 3064 KB |
1_010.txt | AC | 17 ms | 3064 KB |
1_011.txt | AC | 17 ms | 3064 KB |
1_012.txt | AC | 18 ms | 3064 KB |
1_013.txt | AC | 20 ms | 3064 KB |
1_014.txt | AC | 36 ms | 3316 KB |
1_015.txt | AC | 18 ms | 3188 KB |
1_016.txt | AC | 18 ms | 3188 KB |
1_017.txt | AC | 22 ms | 3316 KB |
1_018.txt | AC | 373 ms | 13912 KB |
1_019.txt | AC | 96 ms | 20704 KB |
1_020.txt | AC | 98 ms | 20448 KB |
1_021.txt | AC | 104 ms | 20576 KB |
1_022.txt | AC | 666 ms | 33992 KB |