結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | 👑 rin204 |
提出日時 | 2022-04-16 16:15:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 566 ms / 2,000 ms |
コード長 | 1,974 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 112,448 KB |
最終ジャッジ日時 | 2024-06-07 14:37:39 |
合計ジャッジ時間 | 22,518 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,820 KB |
testcase_01 | AC | 38 ms
53,632 KB |
testcase_02 | AC | 38 ms
53,784 KB |
testcase_03 | AC | 38 ms
52,888 KB |
testcase_04 | AC | 38 ms
53,712 KB |
testcase_05 | AC | 38 ms
54,552 KB |
testcase_06 | AC | 206 ms
81,204 KB |
testcase_07 | AC | 191 ms
80,732 KB |
testcase_08 | AC | 181 ms
80,172 KB |
testcase_09 | AC | 205 ms
81,544 KB |
testcase_10 | AC | 188 ms
81,120 KB |
testcase_11 | AC | 393 ms
98,768 KB |
testcase_12 | AC | 416 ms
98,824 KB |
testcase_13 | AC | 419 ms
98,748 KB |
testcase_14 | AC | 437 ms
99,068 KB |
testcase_15 | AC | 429 ms
98,812 KB |
testcase_16 | AC | 535 ms
112,212 KB |
testcase_17 | AC | 557 ms
111,692 KB |
testcase_18 | AC | 566 ms
111,940 KB |
testcase_19 | AC | 549 ms
111,548 KB |
testcase_20 | AC | 529 ms
111,812 KB |
testcase_21 | AC | 540 ms
111,568 KB |
testcase_22 | AC | 543 ms
111,824 KB |
testcase_23 | AC | 542 ms
111,708 KB |
testcase_24 | AC | 515 ms
111,804 KB |
testcase_25 | AC | 552 ms
111,448 KB |
testcase_26 | AC | 527 ms
93,828 KB |
testcase_27 | AC | 484 ms
94,080 KB |
testcase_28 | AC | 424 ms
94,016 KB |
testcase_29 | AC | 524 ms
94,084 KB |
testcase_30 | AC | 397 ms
94,148 KB |
testcase_31 | AC | 392 ms
91,500 KB |
testcase_32 | AC | 410 ms
94,380 KB |
testcase_33 | AC | 354 ms
94,012 KB |
testcase_34 | AC | 343 ms
87,312 KB |
testcase_35 | AC | 277 ms
83,972 KB |
testcase_36 | AC | 161 ms
91,540 KB |
testcase_37 | AC | 98 ms
78,368 KB |
testcase_38 | AC | 171 ms
93,480 KB |
testcase_39 | AC | 108 ms
80,088 KB |
testcase_40 | AC | 151 ms
88,604 KB |
testcase_41 | AC | 160 ms
90,604 KB |
testcase_42 | AC | 173 ms
93,876 KB |
testcase_43 | AC | 168 ms
91,384 KB |
testcase_44 | AC | 116 ms
81,992 KB |
testcase_45 | AC | 161 ms
90,288 KB |
testcase_46 | AC | 132 ms
79,856 KB |
testcase_47 | AC | 200 ms
92,068 KB |
testcase_48 | AC | 202 ms
87,072 KB |
testcase_49 | AC | 218 ms
94,304 KB |
testcase_50 | AC | 164 ms
83,404 KB |
testcase_51 | AC | 446 ms
104,880 KB |
testcase_52 | AC | 524 ms
112,448 KB |
testcase_53 | AC | 236 ms
84,600 KB |
testcase_54 | AC | 324 ms
93,832 KB |
testcase_55 | AC | 501 ms
111,792 KB |
testcase_56 | AC | 285 ms
88,344 KB |
testcase_57 | AC | 415 ms
101,744 KB |
testcase_58 | AC | 225 ms
81,800 KB |
testcase_59 | AC | 269 ms
88,124 KB |
testcase_60 | AC | 465 ms
111,284 KB |
testcase_61 | AC | 83 ms
76,472 KB |
testcase_62 | AC | 38 ms
53,648 KB |
testcase_63 | AC | 107 ms
76,960 KB |
testcase_64 | AC | 92 ms
77,404 KB |
testcase_65 | AC | 57 ms
65,140 KB |
testcase_66 | AC | 81 ms
76,872 KB |
testcase_67 | AC | 91 ms
77,192 KB |
testcase_68 | AC | 86 ms
76,764 KB |
testcase_69 | AC | 91 ms
77,240 KB |
testcase_70 | AC | 99 ms
77,008 KB |
ソースコード
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[v] != P[u] and UF.same(v, s): flg = True if flg: ans += 1 for u in dic[p]: for v in edges[u]: UF.union(u, v) print(ans)