Submission #3402027
Source Code Expand
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) class UnionFind(): def __init__(self, N): self.par = [i for i in range(N+2)] def root(self, n): if self.par[n] == n: return n else: return self.root(self.par[n]) def isgroup(self, a, b): if self.root(a) == self.root(b): return True else: return False def merge(self, m, n): if self.isgroup(m,n): pass else: self.par[self.root(n)] = self.root(m) N,M = getNM() pos = getList() uf = UnionFind(N) for i in range(M): x, y = getNM() uf.merge(x,y) ans = 0 for i, p in enumerate(pos): if uf.isgroup(i+1, p): #print(i+1, p) ans += 1 else: pass #roots = [uf.root(i) for i in range(N+1)] print(ans)
Submission Info
Submission Time | |
---|---|
Task | D - Equals |
User | socha |
Language | Python (3.4.3) |
Score | 0 |
Code Size | 977 Byte |
Status | RE |
Exec Time | 2104 ms |
Memory | 14452 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 21 ms | 3316 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 | TLE | 2104 ms | 3064 KB |
1_005.txt | TLE | 2104 ms | 13812 KB |
1_006.txt | AC | 1050 ms | 13812 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 | 24 ms | 3064 KB |
1_014.txt | AC | 57 ms | 3064 KB |
1_015.txt | AC | 18 ms | 3064 KB |
1_016.txt | AC | 18 ms | 3064 KB |
1_017.txt | AC | 57 ms | 3188 KB |
1_018.txt | TLE | 2103 ms | 3188 KB |
1_019.txt | AC | 107 ms | 13808 KB |
1_020.txt | AC | 110 ms | 13812 KB |
1_021.txt | AC | 112 ms | 13812 KB |
1_022.txt | RE | 785 ms | 14452 KB |