結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | 👑 rin204 |
提出日時 | 2022-04-16 16:05:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,077 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 82,484 KB |
実行使用メモリ | 112,624 KB |
最終ジャッジ日時 | 2024-06-07 14:36:33 |
合計ジャッジ時間 | 23,221 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,480 KB |
testcase_01 | AC | 38 ms
52,480 KB |
testcase_02 | AC | 38 ms
52,608 KB |
testcase_03 | AC | 38 ms
52,096 KB |
testcase_04 | AC | 39 ms
52,352 KB |
testcase_05 | AC | 40 ms
52,224 KB |
testcase_06 | AC | 195 ms
81,464 KB |
testcase_07 | AC | 175 ms
80,896 KB |
testcase_08 | AC | 176 ms
80,256 KB |
testcase_09 | AC | 192 ms
81,792 KB |
testcase_10 | AC | 183 ms
81,408 KB |
testcase_11 | AC | 361 ms
98,496 KB |
testcase_12 | AC | 383 ms
98,568 KB |
testcase_13 | AC | 401 ms
98,768 KB |
testcase_14 | AC | 368 ms
99,140 KB |
testcase_15 | AC | 455 ms
98,756 KB |
testcase_16 | AC | 516 ms
111,756 KB |
testcase_17 | AC | 557 ms
111,496 KB |
testcase_18 | AC | 509 ms
111,764 KB |
testcase_19 | AC | 525 ms
111,876 KB |
testcase_20 | AC | 515 ms
111,752 KB |
testcase_21 | AC | 510 ms
111,748 KB |
testcase_22 | AC | 494 ms
111,504 KB |
testcase_23 | AC | 517 ms
111,636 KB |
testcase_24 | AC | 485 ms
111,624 KB |
testcase_25 | AC | 530 ms
111,628 KB |
testcase_26 | AC | 524 ms
93,696 KB |
testcase_27 | AC | 524 ms
93,708 KB |
testcase_28 | AC | 431 ms
93,856 KB |
testcase_29 | AC | 543 ms
94,208 KB |
testcase_30 | AC | 307 ms
101,512 KB |
testcase_31 | AC | 413 ms
91,136 KB |
testcase_32 | AC | 429 ms
93,848 KB |
testcase_33 | AC | 342 ms
93,440 KB |
testcase_34 | AC | 342 ms
87,296 KB |
testcase_35 | AC | 284 ms
84,448 KB |
testcase_36 | AC | 163 ms
91,136 KB |
testcase_37 | AC | 99 ms
78,080 KB |
testcase_38 | AC | 176 ms
93,916 KB |
testcase_39 | AC | 109 ms
79,872 KB |
testcase_40 | AC | 152 ms
88,064 KB |
testcase_41 | AC | 162 ms
89,856 KB |
testcase_42 | AC | 176 ms
93,952 KB |
testcase_43 | AC | 164 ms
91,392 KB |
testcase_44 | AC | 118 ms
81,920 KB |
testcase_45 | AC | 159 ms
89,856 KB |
testcase_46 | AC | 127 ms
80,000 KB |
testcase_47 | AC | 189 ms
92,032 KB |
testcase_48 | WA | - |
testcase_49 | AC | 200 ms
93,784 KB |
testcase_50 | AC | 152 ms
83,392 KB |
testcase_51 | AC | 405 ms
105,076 KB |
testcase_52 | AC | 519 ms
112,624 KB |
testcase_53 | AC | 250 ms
85,120 KB |
testcase_54 | AC | 324 ms
93,544 KB |
testcase_55 | AC | 509 ms
111,844 KB |
testcase_56 | AC | 270 ms
88,192 KB |
testcase_57 | AC | 362 ms
101,316 KB |
testcase_58 | AC | 202 ms
80,872 KB |
testcase_59 | AC | 294 ms
87,936 KB |
testcase_60 | AC | 476 ms
111,472 KB |
testcase_61 | AC | 80 ms
76,740 KB |
testcase_62 | AC | 39 ms
52,736 KB |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | AC | 55 ms
64,384 KB |
testcase_66 | AC | 74 ms
74,496 KB |
testcase_67 | AC | 84 ms
76,672 KB |
testcase_68 | AC | 80 ms
76,544 KB |
testcase_69 | AC | 83 ms
76,772 KB |
testcase_70 | WA | - |
ソースコード
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n self.group = n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return self.group -= 1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return self.group def all_group_members(self): dic = {r:[] for r in self.roots()} for i in range(self.n): dic[self.find(i)].append(i) return dic def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, m, s, t = map(int, input().split()) P = list(map(int, input().split())) s -= 1 t -= 1 edges = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 if P[a] > P[b]: a, b = b, a edges[a].append(b) dic = {} for i, p in enumerate(P): if p not in dic: dic[p] = [] dic[p].append(i) ans = 0 UF = UnionFind(n) for p in sorted(dic.keys(), reverse = True): flg = False tmp = [] for u in dic[p]: for v in edges[u]: if P[u] == P[v]: tmp.append((u, v)) else: if not UF.same(u, v): if UF.same(v, s): flg = True UF.union(u, v) ans += flg for u, v in tmp: UF.union(u, v) print(ans)