結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | 👑 rin204 |
提出日時 | 2022-04-16 16:14:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,957 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 81,900 KB |
実行使用メモリ | 112,700 KB |
最終ジャッジ日時 | 2024-06-07 14:37:16 |
合計ジャッジ時間 | 22,829 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,956 KB |
testcase_01 | AC | 40 ms
53,868 KB |
testcase_02 | AC | 39 ms
53,560 KB |
testcase_03 | AC | 38 ms
52,880 KB |
testcase_04 | AC | 39 ms
53,532 KB |
testcase_05 | AC | 39 ms
53,672 KB |
testcase_06 | AC | 201 ms
81,228 KB |
testcase_07 | AC | 203 ms
80,964 KB |
testcase_08 | AC | 183 ms
80,352 KB |
testcase_09 | AC | 206 ms
81,500 KB |
testcase_10 | AC | 186 ms
81,336 KB |
testcase_11 | AC | 381 ms
98,716 KB |
testcase_12 | AC | 416 ms
98,748 KB |
testcase_13 | AC | 418 ms
98,952 KB |
testcase_14 | AC | 442 ms
98,956 KB |
testcase_15 | AC | 432 ms
98,584 KB |
testcase_16 | AC | 520 ms
111,548 KB |
testcase_17 | AC | 573 ms
111,808 KB |
testcase_18 | AC | 576 ms
111,948 KB |
testcase_19 | AC | 575 ms
111,564 KB |
testcase_20 | AC | 534 ms
111,816 KB |
testcase_21 | AC | 560 ms
111,676 KB |
testcase_22 | AC | 562 ms
111,568 KB |
testcase_23 | AC | 574 ms
111,696 KB |
testcase_24 | AC | 522 ms
111,424 KB |
testcase_25 | AC | 573 ms
111,832 KB |
testcase_26 | WA | - |
testcase_27 | AC | 474 ms
93,652 KB |
testcase_28 | WA | - |
testcase_29 | AC | 496 ms
94,072 KB |
testcase_30 | AC | 403 ms
94,192 KB |
testcase_31 | AC | 386 ms
91,656 KB |
testcase_32 | AC | 393 ms
93,896 KB |
testcase_33 | AC | 338 ms
93,652 KB |
testcase_34 | AC | 325 ms
87,724 KB |
testcase_35 | AC | 263 ms
83,852 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 | 128 ms
80,200 KB |
testcase_47 | AC | 197 ms
91,672 KB |
testcase_48 | AC | 197 ms
87,212 KB |
testcase_49 | AC | 203 ms
94,240 KB |
testcase_50 | AC | 153 ms
83,864 KB |
testcase_51 | AC | 441 ms
105,020 KB |
testcase_52 | AC | 499 ms
112,700 KB |
testcase_53 | AC | 233 ms
84,420 KB |
testcase_54 | AC | 325 ms
93,640 KB |
testcase_55 | AC | 503 ms
111,896 KB |
testcase_56 | AC | 277 ms
88,384 KB |
testcase_57 | AC | 404 ms
101,340 KB |
testcase_58 | AC | 220 ms
81,452 KB |
testcase_59 | AC | 278 ms
88,012 KB |
testcase_60 | AC | 474 ms
111,420 KB |
testcase_61 | WA | - |
testcase_62 | AC | 39 ms
54,656 KB |
testcase_63 | AC | 110 ms
76,968 KB |
testcase_64 | AC | 92 ms
76,628 KB |
testcase_65 | AC | 56 ms
65,484 KB |
testcase_66 | WA | - |
testcase_67 | AC | 91 ms
76,792 KB |
testcase_68 | WA | - |
testcase_69 | AC | 90 ms
76,788 KB |
testcase_70 | AC | 97 ms
77,308 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)