結果

問題 No.1382 Travel in Mitaru city
ユーザー MitarushiMitarushi
提出日時 2021-02-04 21:58:01
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,475 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 101,932 KB
最終ジャッジ日時 2023-09-17 06:31:06
合計ジャッジ時間 28,409 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,356 KB
testcase_01 WA -
testcase_02 AC 71 ms
71,364 KB
testcase_03 AC 74 ms
71,368 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 281 ms
83,716 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 286 ms
83,892 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 459 ms
91,288 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 672 ms
98,676 KB
testcase_24 AC 663 ms
97,948 KB
testcase_25 AC 678 ms
98,592 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 541 ms
95,656 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 445 ms
91,148 KB
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 72 ms
71,216 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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)])
0