結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | 👑 rin204 |
提出日時 | 2022-04-16 16:14:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,957 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 112,640 KB |
最終ジャッジ日時 | 2024-12-25 20:18:42 |
合計ジャッジ時間 | 28,472 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
52,096 KB |
testcase_01 | AC | 48 ms
52,480 KB |
testcase_02 | AC | 50 ms
52,096 KB |
testcase_03 | AC | 51 ms
52,096 KB |
testcase_04 | AC | 48 ms
52,224 KB |
testcase_05 | AC | 49 ms
52,224 KB |
testcase_06 | AC | 250 ms
81,536 KB |
testcase_07 | AC | 240 ms
80,640 KB |
testcase_08 | AC | 226 ms
80,384 KB |
testcase_09 | AC | 258 ms
81,664 KB |
testcase_10 | AC | 240 ms
81,024 KB |
testcase_11 | AC | 472 ms
98,760 KB |
testcase_12 | AC | 525 ms
98,700 KB |
testcase_13 | AC | 529 ms
98,584 KB |
testcase_14 | AC | 544 ms
99,148 KB |
testcase_15 | AC | 526 ms
98,892 KB |
testcase_16 | AC | 631 ms
111,888 KB |
testcase_17 | AC | 684 ms
111,508 KB |
testcase_18 | AC | 684 ms
111,760 KB |
testcase_19 | AC | 717 ms
111,504 KB |
testcase_20 | AC | 647 ms
112,008 KB |
testcase_21 | AC | 666 ms
111,496 KB |
testcase_22 | AC | 661 ms
111,500 KB |
testcase_23 | AC | 695 ms
111,624 KB |
testcase_24 | AC | 623 ms
111,504 KB |
testcase_25 | AC | 688 ms
111,624 KB |
testcase_26 | WA | - |
testcase_27 | AC | 581 ms
94,080 KB |
testcase_28 | WA | - |
testcase_29 | AC | 604 ms
93,952 KB |
testcase_30 | AC | 480 ms
93,952 KB |
testcase_31 | AC | 461 ms
91,136 KB |
testcase_32 | AC | 484 ms
93,568 KB |
testcase_33 | AC | 436 ms
93,440 KB |
testcase_34 | AC | 408 ms
86,912 KB |
testcase_35 | AC | 333 ms
84,036 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 165 ms
80,256 KB |
testcase_47 | AC | 246 ms
92,160 KB |
testcase_48 | AC | 249 ms
86,912 KB |
testcase_49 | AC | 259 ms
94,080 KB |
testcase_50 | AC | 200 ms
83,072 KB |
testcase_51 | AC | 536 ms
105,076 KB |
testcase_52 | AC | 620 ms
112,640 KB |
testcase_53 | AC | 288 ms
84,608 KB |
testcase_54 | AC | 392 ms
93,568 KB |
testcase_55 | AC | 610 ms
111,852 KB |
testcase_56 | AC | 339 ms
88,320 KB |
testcase_57 | AC | 490 ms
101,416 KB |
testcase_58 | AC | 273 ms
81,560 KB |
testcase_59 | AC | 346 ms
87,808 KB |
testcase_60 | AC | 574 ms
110,924 KB |
testcase_61 | WA | - |
testcase_62 | AC | 52 ms
52,736 KB |
testcase_63 | AC | 145 ms
76,544 KB |
testcase_64 | AC | 120 ms
76,800 KB |
testcase_65 | AC | 76 ms
65,152 KB |
testcase_66 | WA | - |
testcase_67 | AC | 122 ms
76,928 KB |
testcase_68 | WA | - |
testcase_69 | AC | 121 ms
76,544 KB |
testcase_70 | AC | 127 ms
77,312 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 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)