結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | Mitarushi |
提出日時 | 2021-02-04 23:35:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,687 bytes |
コンパイル時間 | 271 ms |
コンパイル使用メモリ | 86,988 KB |
実行使用メモリ | 110,304 KB |
最終ジャッジ日時 | 2023-09-17 06:32:49 |
合計ジャッジ時間 | 31,003 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,276 KB |
testcase_01 | AC | 72 ms
71,196 KB |
testcase_02 | AC | 72 ms
71,256 KB |
testcase_03 | AC | 73 ms
71,376 KB |
testcase_04 | AC | 74 ms
71,092 KB |
testcase_05 | WA | - |
testcase_06 | AC | 332 ms
92,808 KB |
testcase_07 | AC | 293 ms
88,940 KB |
testcase_08 | AC | 246 ms
83,788 KB |
testcase_09 | AC | 343 ms
93,500 KB |
testcase_10 | AC | 335 ms
92,904 KB |
testcase_11 | WA | - |
testcase_12 | AC | 533 ms
98,976 KB |
testcase_13 | AC | 553 ms
100,924 KB |
testcase_14 | AC | 501 ms
97,472 KB |
testcase_15 | AC | 510 ms
98,956 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 755 ms
107,940 KB |
testcase_19 | WA | - |
testcase_20 | AC | 737 ms
107,820 KB |
testcase_21 | AC | 730 ms
107,744 KB |
testcase_22 | AC | 729 ms
107,636 KB |
testcase_23 | AC | 735 ms
107,680 KB |
testcase_24 | AC | 750 ms
107,536 KB |
testcase_25 | AC | 767 ms
108,572 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
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 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 587 ms
103,844 KB |
testcase_52 | AC | 666 ms
108,428 KB |
testcase_53 | AC | 271 ms
85,316 KB |
testcase_54 | AC | 379 ms
92,208 KB |
testcase_55 | AC | 659 ms
107,768 KB |
testcase_56 | AC | 320 ms
88,060 KB |
testcase_57 | AC | 488 ms
98,564 KB |
testcase_58 | AC | 218 ms
82,448 KB |
testcase_59 | AC | 312 ms
88,008 KB |
testcase_60 | AC | 648 ms
108,224 KB |
testcase_61 | WA | - |
testcase_62 | AC | 73 ms
71,196 KB |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
ソースコード
# 制約違反チェック 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), ind) for ind, i in enumerate(input().split())] p.sort(reverse=True) assert 1<=p[0][0] <= 10**9 and 1<=p[-1][0] <= 10**9 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 _, ind in p: used[ind] = True if ind == s: a = 0 else: a = -float("inf") for j in e[ind]: if used[j]: a = max(a, dp[uf.get_root(j)]) a += 1 for j in e[ind]: if used[j]: uf.merge(ind, j) dp[uf.get_root(ind)] = a print(dp[uf.get_root(t)])