結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | 👑 rin204 |
提出日時 | 2022-04-16 16:05:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,077 bytes |
コンパイル時間 | 524 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 112,764 KB |
最終ジャッジ日時 | 2024-12-25 20:17:51 |
合計ジャッジ時間 | 25,521 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,480 KB |
testcase_01 | AC | 40 ms
52,608 KB |
testcase_02 | AC | 40 ms
52,224 KB |
testcase_03 | AC | 40 ms
52,608 KB |
testcase_04 | AC | 42 ms
52,096 KB |
testcase_05 | AC | 42 ms
52,480 KB |
testcase_06 | AC | 289 ms
81,408 KB |
testcase_07 | AC | 190 ms
80,768 KB |
testcase_08 | AC | 213 ms
80,256 KB |
testcase_09 | AC | 210 ms
81,408 KB |
testcase_10 | AC | 197 ms
81,408 KB |
testcase_11 | AC | 389 ms
98,508 KB |
testcase_12 | AC | 410 ms
98,876 KB |
testcase_13 | AC | 426 ms
98,764 KB |
testcase_14 | AC | 416 ms
99,156 KB |
testcase_15 | AC | 479 ms
98,624 KB |
testcase_16 | AC | 574 ms
112,276 KB |
testcase_17 | AC | 595 ms
111,756 KB |
testcase_18 | AC | 562 ms
111,756 KB |
testcase_19 | AC | 547 ms
111,616 KB |
testcase_20 | AC | 564 ms
111,748 KB |
testcase_21 | AC | 545 ms
111,884 KB |
testcase_22 | AC | 521 ms
111,876 KB |
testcase_23 | AC | 570 ms
111,756 KB |
testcase_24 | AC | 525 ms
111,496 KB |
testcase_25 | AC | 582 ms
111,872 KB |
testcase_26 | AC | 557 ms
93,952 KB |
testcase_27 | AC | 567 ms
94,080 KB |
testcase_28 | AC | 472 ms
93,952 KB |
testcase_29 | AC | 590 ms
93,952 KB |
testcase_30 | AC | 332 ms
101,384 KB |
testcase_31 | AC | 459 ms
91,648 KB |
testcase_32 | AC | 453 ms
93,824 KB |
testcase_33 | AC | 377 ms
93,440 KB |
testcase_34 | AC | 388 ms
87,552 KB |
testcase_35 | AC | 329 ms
84,192 KB |
testcase_36 | AC | 174 ms
91,264 KB |
testcase_37 | AC | 112 ms
77,952 KB |
testcase_38 | AC | 189 ms
93,824 KB |
testcase_39 | AC | 127 ms
80,000 KB |
testcase_40 | AC | 176 ms
88,320 KB |
testcase_41 | AC | 185 ms
89,856 KB |
testcase_42 | AC | 195 ms
94,080 KB |
testcase_43 | AC | 183 ms
91,136 KB |
testcase_44 | AC | 141 ms
81,920 KB |
testcase_45 | AC | 173 ms
89,856 KB |
testcase_46 | AC | 137 ms
79,872 KB |
testcase_47 | AC | 215 ms
92,160 KB |
testcase_48 | WA | - |
testcase_49 | AC | 226 ms
93,824 KB |
testcase_50 | AC | 177 ms
83,748 KB |
testcase_51 | AC | 453 ms
104,828 KB |
testcase_52 | AC | 576 ms
112,764 KB |
testcase_53 | AC | 284 ms
85,248 KB |
testcase_54 | AC | 363 ms
93,440 KB |
testcase_55 | AC | 611 ms
111,716 KB |
testcase_56 | AC | 298 ms
88,192 KB |
testcase_57 | AC | 407 ms
101,268 KB |
testcase_58 | AC | 223 ms
81,160 KB |
testcase_59 | AC | 308 ms
88,064 KB |
testcase_60 | AC | 512 ms
111,732 KB |
testcase_61 | AC | 95 ms
76,544 KB |
testcase_62 | AC | 45 ms
52,864 KB |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | AC | 65 ms
64,000 KB |
testcase_66 | AC | 87 ms
74,496 KB |
testcase_67 | AC | 97 ms
76,544 KB |
testcase_68 | AC | 99 ms
76,288 KB |
testcase_69 | AC | 93 ms
76,672 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)