Submission #3967355
Source Code Expand
N,M=map(int,input().split()) par=[0 for i in range(N)] rnk=[0 for i in range(N)] def init(n): for i in range(N): par[i]=i rnk[i]=0 def find(x): if par[x]==x: return x else: par[x]=find(par[x]) return par[x] def unite(x,y): x=find(x) y=find(y) if x==y: return if (rnk[x]<rnk[y]): par[x]=y else: par[y]=x if(rnk[x]==rnk[y]): rnk[x]+=1 def same(x,y): return find(x)==find(y) p=[int(i)-1 for i in input().split()] init(N) for i in range(M): x,y=map(int,input().split()) unite(x-1,y-1) ans=0 for i in range(N): if same(i,p[i]): ans+=1 print(ans)
Submission Info
Submission Time | |
---|---|
Task | D - Equals |
User | shakayami |
Language | Python (3.4.3) |
Score | 400 |
Code Size | 719 Byte |
Status | AC |
Exec Time | 599 ms |
Memory | 15408 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 | 387 ms | 3064 KB |
1_005.txt | AC | 476 ms | 15408 KB |
1_006.txt | AC | 599 ms | 15408 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 | 21 ms | 3064 KB |
1_014.txt | AC | 36 ms | 3064 KB |
1_015.txt | AC | 18 ms | 3064 KB |
1_016.txt | AC | 19 ms | 3064 KB |
1_017.txt | AC | 23 ms | 3064 KB |
1_018.txt | AC | 344 ms | 3188 KB |
1_019.txt | AC | 112 ms | 15408 KB |
1_020.txt | AC | 115 ms | 15408 KB |
1_021.txt | AC | 114 ms | 15408 KB |
1_022.txt | AC | 570 ms | 15408 KB |