結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | Mitarushi |
提出日時 | 2021-02-07 15:39:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 774 ms / 2,000 ms |
コード長 | 1,917 bytes |
コンパイル時間 | 1,322 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 120,248 KB |
最終ジャッジ日時 | 2024-07-04 03:47:02 |
合計ジャッジ時間 | 25,796 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,992 KB |
testcase_01 | AC | 37 ms
52,608 KB |
testcase_02 | AC | 36 ms
52,608 KB |
testcase_03 | AC | 34 ms
52,992 KB |
testcase_04 | AC | 37 ms
52,224 KB |
testcase_05 | AC | 35 ms
52,480 KB |
testcase_06 | AC | 314 ms
93,648 KB |
testcase_07 | AC | 287 ms
89,680 KB |
testcase_08 | AC | 223 ms
84,192 KB |
testcase_09 | AC | 299 ms
95,108 KB |
testcase_10 | AC | 275 ms
93,324 KB |
testcase_11 | AC | 440 ms
103,692 KB |
testcase_12 | AC | 465 ms
105,668 KB |
testcase_13 | AC | 494 ms
105,628 KB |
testcase_14 | AC | 436 ms
103,260 KB |
testcase_15 | AC | 461 ms
103,612 KB |
testcase_16 | AC | 590 ms
118,728 KB |
testcase_17 | AC | 621 ms
119,216 KB |
testcase_18 | AC | 669 ms
119,944 KB |
testcase_19 | AC | 595 ms
120,248 KB |
testcase_20 | AC | 625 ms
119,920 KB |
testcase_21 | AC | 615 ms
119,992 KB |
testcase_22 | AC | 611 ms
118,960 KB |
testcase_23 | AC | 617 ms
119,740 KB |
testcase_24 | AC | 590 ms
119,360 KB |
testcase_25 | AC | 611 ms
120,240 KB |
testcase_26 | AC | 483 ms
107,632 KB |
testcase_27 | AC | 501 ms
107,372 KB |
testcase_28 | AC | 456 ms
107,828 KB |
testcase_29 | AC | 474 ms
107,824 KB |
testcase_30 | AC | 406 ms
110,092 KB |
testcase_31 | AC | 387 ms
101,464 KB |
testcase_32 | AC | 470 ms
107,064 KB |
testcase_33 | AC | 444 ms
105,248 KB |
testcase_34 | AC | 346 ms
96,460 KB |
testcase_35 | AC | 294 ms
88,808 KB |
testcase_36 | AC | 255 ms
103,564 KB |
testcase_37 | AC | 127 ms
81,400 KB |
testcase_38 | AC | 272 ms
107,284 KB |
testcase_39 | AC | 155 ms
84,748 KB |
testcase_40 | AC | 232 ms
97,652 KB |
testcase_41 | AC | 233 ms
99,020 KB |
testcase_42 | AC | 262 ms
103,988 KB |
testcase_43 | AC | 241 ms
99,480 KB |
testcase_44 | AC | 159 ms
85,528 KB |
testcase_45 | AC | 247 ms
98,076 KB |
testcase_46 | AC | 185 ms
86,016 KB |
testcase_47 | AC | 315 ms
105,788 KB |
testcase_48 | AC | 270 ms
97,380 KB |
testcase_49 | AC | 345 ms
108,608 KB |
testcase_50 | AC | 228 ms
91,732 KB |
testcase_51 | AC | 461 ms
113,072 KB |
testcase_52 | AC | 774 ms
120,140 KB |
testcase_53 | AC | 272 ms
87,552 KB |
testcase_54 | AC | 332 ms
97,892 KB |
testcase_55 | AC | 517 ms
118,716 KB |
testcase_56 | AC | 290 ms
90,744 KB |
testcase_57 | AC | 384 ms
105,468 KB |
testcase_58 | AC | 219 ms
83,820 KB |
testcase_59 | AC | 278 ms
90,096 KB |
testcase_60 | AC | 483 ms
117,000 KB |
testcase_61 | AC | 97 ms
76,716 KB |
testcase_62 | AC | 36 ms
52,864 KB |
testcase_63 | AC | 134 ms
80,540 KB |
testcase_64 | AC | 105 ms
77,128 KB |
testcase_65 | AC | 68 ms
69,352 KB |
testcase_66 | AC | 93 ms
76,608 KB |
testcase_67 | AC | 106 ms
77,312 KB |
testcase_68 | AC | 115 ms
77,952 KB |
testcase_69 | AC | 102 ms
76,800 KB |
testcase_70 | AC | 114 ms
78,720 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()) assert 2<=n<=10**5 and 1<=m<=10**5, 1<=s<=n and 1<=t<=n assert s != t s -= 1 t -= 1 p = [int(i) for i in input().split()] assert 1<=min(p) <= 10**9 and 1<=max(p) <= 10**9 pd = {} for ind, i in enumerate(p): if i not in pd: pd[i] = [] pd[i].append(ind) ss = set() e = [[] for _ in range(n)] for _ in range(m): a, b = [int(i) - 1 for i in input().split()] assert a<b e[a].append(b) e[b].append(a) assert (a,b) not in ss ss.add((a,b)) 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)])