結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | Mitarushi |
提出日時 | 2021-02-05 20:11:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 673 ms / 2,000 ms |
コード長 | 1,727 bytes |
コンパイル時間 | 152 ms |
コンパイル使用メモリ | 82,264 KB |
実行使用メモリ | 110,148 KB |
最終ジャッジ日時 | 2024-07-04 03:38:52 |
合計ジャッジ時間 | 25,304 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,448 KB |
testcase_01 | AC | 37 ms
53,104 KB |
testcase_02 | AC | 40 ms
53,036 KB |
testcase_03 | AC | 38 ms
52,836 KB |
testcase_04 | AC | 38 ms
53,868 KB |
testcase_05 | AC | 37 ms
54,272 KB |
testcase_06 | AC | 275 ms
84,836 KB |
testcase_07 | AC | 248 ms
83,844 KB |
testcase_08 | AC | 212 ms
81,784 KB |
testcase_09 | AC | 284 ms
85,100 KB |
testcase_10 | AC | 265 ms
84,388 KB |
testcase_11 | AC | 455 ms
97,768 KB |
testcase_12 | AC | 478 ms
98,000 KB |
testcase_13 | AC | 480 ms
98,156 KB |
testcase_14 | AC | 457 ms
97,828 KB |
testcase_15 | AC | 461 ms
98,020 KB |
testcase_16 | AC | 608 ms
108,932 KB |
testcase_17 | AC | 633 ms
108,804 KB |
testcase_18 | AC | 673 ms
109,812 KB |
testcase_19 | AC | 621 ms
109,064 KB |
testcase_20 | AC | 643 ms
109,828 KB |
testcase_21 | AC | 628 ms
109,576 KB |
testcase_22 | AC | 625 ms
109,420 KB |
testcase_23 | AC | 643 ms
108,916 KB |
testcase_24 | AC | 603 ms
108,808 KB |
testcase_25 | AC | 645 ms
109,192 KB |
testcase_26 | AC | 521 ms
97,660 KB |
testcase_27 | AC | 492 ms
97,116 KB |
testcase_28 | AC | 467 ms
97,792 KB |
testcase_29 | AC | 478 ms
98,048 KB |
testcase_30 | AC | 423 ms
98,036 KB |
testcase_31 | AC | 404 ms
92,932 KB |
testcase_32 | AC | 485 ms
96,076 KB |
testcase_33 | AC | 453 ms
94,664 KB |
testcase_34 | AC | 366 ms
89,636 KB |
testcase_35 | AC | 291 ms
85,956 KB |
testcase_36 | AC | 247 ms
94,992 KB |
testcase_37 | AC | 125 ms
79,528 KB |
testcase_38 | AC | 259 ms
97,172 KB |
testcase_39 | AC | 145 ms
82,152 KB |
testcase_40 | AC | 217 ms
90,940 KB |
testcase_41 | AC | 223 ms
90,664 KB |
testcase_42 | AC | 251 ms
93,532 KB |
testcase_43 | AC | 233 ms
91,368 KB |
testcase_44 | AC | 148 ms
83,808 KB |
testcase_45 | AC | 219 ms
89,952 KB |
testcase_46 | AC | 180 ms
83,388 KB |
testcase_47 | AC | 319 ms
96,760 KB |
testcase_48 | AC | 277 ms
90,956 KB |
testcase_49 | AC | 330 ms
98,660 KB |
testcase_50 | AC | 229 ms
88,024 KB |
testcase_51 | AC | 478 ms
104,344 KB |
testcase_52 | AC | 539 ms
110,148 KB |
testcase_53 | AC | 250 ms
85,676 KB |
testcase_54 | AC | 332 ms
93,080 KB |
testcase_55 | AC | 536 ms
109,064 KB |
testcase_56 | AC | 290 ms
88,608 KB |
testcase_57 | AC | 394 ms
99,664 KB |
testcase_58 | AC | 221 ms
82,804 KB |
testcase_59 | AC | 285 ms
87,852 KB |
testcase_60 | AC | 502 ms
108,296 KB |
testcase_61 | AC | 91 ms
76,600 KB |
testcase_62 | AC | 37 ms
52,984 KB |
testcase_63 | AC | 125 ms
77,412 KB |
testcase_64 | AC | 97 ms
76,652 KB |
testcase_65 | AC | 64 ms
69,852 KB |
testcase_66 | AC | 88 ms
76,672 KB |
testcase_67 | AC | 96 ms
76,780 KB |
testcase_68 | AC | 97 ms
76,704 KB |
testcase_69 | AC | 91 ms
76,872 KB |
testcase_70 | AC | 105 ms
77,024 KB |
ソースコード
class UnionFind: def __init__(self, n): self.parent = [-1] * n self.rank = [1] * n self.count = [1] * n def get_root(self, i): while self.parent[i] != -1: i = self.parent[i] return i def is_same_tree(self, i, j): return self.get_root(i) == self.get_root(j) def merge(self, i, j): i = self.get_root(i) j = self.get_root(j) if i == j: return if self.rank[i] > self.rank[j]: self.parent[j] = i self.rank[i] = max(self.rank[i], self.rank[j] + 1) self.count[i] += self.count[j] else: self.parent[i] = j self.rank[j] = max(self.rank[j], self.rank[i] + 1) self.count[j] += self.count[i] n, m, s, t = map(int, input().split()) s -= 1 t -= 1 p = [int(i) for i in input().split()] pd = {} for ind, i in enumerate(p): if i not in pd: pd[i] = [] pd[i].append(ind) e = [[] for _ in range(n)] for _ in range(m): a, b = [int(i) - 1 for i in input().split()] e[a].append(b) e[b].append(a) uf = UnionFind(n) dp = [-float("inf")] * n used = [False] * n for p_key in sorted(pd.keys(), reverse=True): a = [] for i in pd[p_key]: if i == s: a.append(0) else: aa = -float("inf") for j in e[i]: if used[j]: aa = max(aa, dp[uf.get_root(j)]) a.append(aa+1) for i in pd[p_key]: used[i] = True for j in e[i]: if used[j]: uf.merge(i, j) for i, aa in zip(pd[p_key], a): r = uf.get_root(i) dp[r] = max(dp[r], aa) print(dp[uf.get_root(t)])