結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | Mitarushi |
提出日時 | 2021-02-04 23:35:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,687 bytes |
コンパイル時間 | 206 ms |
コンパイル使用メモリ | 82,188 KB |
実行使用メモリ | 108,620 KB |
最終ジャッジ日時 | 2024-07-04 03:38:01 |
合計ジャッジ時間 | 26,486 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,536 KB |
testcase_01 | AC | 40 ms
52,864 KB |
testcase_02 | AC | 38 ms
52,096 KB |
testcase_03 | AC | 40 ms
52,480 KB |
testcase_04 | AC | 37 ms
52,352 KB |
testcase_05 | WA | - |
testcase_06 | AC | 266 ms
90,288 KB |
testcase_07 | AC | 234 ms
88,580 KB |
testcase_08 | AC | 205 ms
82,852 KB |
testcase_09 | AC | 285 ms
92,440 KB |
testcase_10 | AC | 281 ms
90,412 KB |
testcase_11 | WA | - |
testcase_12 | AC | 440 ms
98,096 KB |
testcase_13 | AC | 470 ms
99,392 KB |
testcase_14 | AC | 432 ms
95,808 KB |
testcase_15 | AC | 467 ms
96,836 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 668 ms
107,032 KB |
testcase_19 | WA | - |
testcase_20 | AC | 659 ms
106,320 KB |
testcase_21 | AC | 666 ms
106,756 KB |
testcase_22 | AC | 643 ms
107,004 KB |
testcase_23 | AC | 633 ms
106,360 KB |
testcase_24 | AC | 672 ms
106,500 KB |
testcase_25 | AC | 685 ms
107,096 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 | 528 ms
103,836 KB |
testcase_52 | AC | 599 ms
107,840 KB |
testcase_53 | AC | 222 ms
83,340 KB |
testcase_54 | AC | 328 ms
91,488 KB |
testcase_55 | AC | 559 ms
107,216 KB |
testcase_56 | AC | 261 ms
87,136 KB |
testcase_57 | AC | 416 ms
96,712 KB |
testcase_58 | AC | 174 ms
80,876 KB |
testcase_59 | AC | 256 ms
86,148 KB |
testcase_60 | AC | 548 ms
105,644 KB |
testcase_61 | WA | - |
testcase_62 | AC | 38 ms
52,736 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)])