結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | Mitarushi |
提出日時 | 2021-02-04 21:58:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,475 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 81,944 KB |
実行使用メモリ | 99,360 KB |
最終ジャッジ日時 | 2024-07-04 03:36:33 |
合計ジャッジ時間 | 24,549 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,096 KB |
testcase_01 | WA | - |
testcase_02 | AC | 38 ms
52,480 KB |
testcase_03 | AC | 38 ms
52,480 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 242 ms
82,584 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 247 ms
82,400 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 431 ms
89,516 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 603 ms
96,712 KB |
testcase_24 | AC | 596 ms
97,228 KB |
testcase_25 | AC | 617 ms
97,288 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 | 467 ms
94,336 KB |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | AC | 381 ms
90,036 KB |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | AC | 38 ms
52,352 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()) s -= 1 t -= 1 p = [(int(i), ind) for ind, i in enumerate(input().split())] p.sort(reverse=True) 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 _, 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)]) for j in e[ind]: if used[j]: uf.merge(ind, j) a += 1 dp[uf.get_root(ind)] = a print(dp[uf.get_root(t)])