Submission #2561077
Source Code Expand
N, M = input().split() N = int(N) M = int(M) pList = input().split() pairList = [] indexList = [0 for _ in range(N+1)] groupNum = 1 for i in range(M): thisPair = input().split() p1 = int(thisPair[0]) p2 = int(thisPair[1]) if indexList[p1] == 0 and indexList[p2] == 0: indexList[p1] = groupNum indexList[p2] = groupNum groupNum += 1 elif indexList[p1] == 0 and indexList[p2] != 0: indexList[p1] = indexList[p2] elif indexList[p1] != 0 and indexList[p2] == 0: indexList[p2] = indexList[p1] else: unifiedGroup = indexList[p1] for i in range(len(indexList)): if indexList[i] == unifiedGroup: indexList[i] = indexList[p2] # print(indexList) groupMap = {} for i in range(len(indexList)): if str(indexList[i]) in groupMap.keys(): groupMap[str(indexList[i])].append(i) else: groupMap[str(indexList[i])] = [i] # print(pList) # print(groupMap) # print(indexList) res = 0 for i in range(1,len(pList)+1): if i == int(pList[i-1]): # print(i) res += 1 else: groupName = str(indexList[i]) if i in groupMap[groupName] and int(pList[i-1]) in groupMap[groupName]: # print(i, 'a') res += 1 print(res)
Submission Info
Submission Time | |
---|---|
Task | D - Equals |
User | kikkakesan |
Language | Python (3.4.3) |
Score | 0 |
Code Size | 1337 Byte |
Status | WA |
Exec Time | 2104 ms |
Memory | 14740 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 | 18 ms | 3064 KB |
0_001.txt | AC | 18 ms | 3064 KB |
0_002.txt | AC | 18 ms | 3064 KB |
0_003.txt | AC | 18 ms | 3064 KB |
1_004.txt | TLE | 2103 ms | 3064 KB |
1_005.txt | TLE | 2104 ms | 10740 KB |
1_006.txt | TLE | 2104 ms | 11124 KB |
1_007.txt | AC | 18 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 | WA | 17 ms | 3064 KB |
1_012.txt | AC | 18 ms | 3064 KB |
1_013.txt | AC | 35 ms | 3064 KB |
1_014.txt | AC | 120 ms | 3064 KB |
1_015.txt | WA | 32 ms | 3188 KB |
1_016.txt | WA | 29 ms | 3064 KB |
1_017.txt | WA | 79 ms | 3064 KB |
1_018.txt | TLE | 2103 ms | 3188 KB |
1_019.txt | TLE | 2104 ms | 14732 KB |
1_020.txt | TLE | 2104 ms | 14612 KB |
1_021.txt | TLE | 2104 ms | 14740 KB |
1_022.txt | TLE | 2104 ms | 10996 KB |