結果

問題 No.1995 CHIKA Road
ユーザー ryusukeryusuke
提出日時 2022-07-01 22:29:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 97,336 KB
最終ジャッジ日時 2024-05-04 16:48:05
合計ジャッジ時間 4,614 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
58,880 KB
testcase_01 AC 42 ms
53,504 KB
testcase_02 AC 39 ms
53,504 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def dfs(now: int, prev: int):
    for nxt in g[now]:
        if nxt == prev:
            continue
        dist[nxt] = max(dist[nxt], dist[now] + 1)
        dfs(nxt, now)

n, m = map(int, input().split())

g_rev = defaultdict(list)
g = defaultdict(list)
visited = set()
for _ in range(m):
    a, b = map(int, input().split())
    visited.add(a)
    visited.add(b)
    g[a].append(b)
    g_rev[b].append(a)

visited = list(visited)
s_list = []
dist = defaultdict(lambda : -10 ** 18)
for start in visited:
    if g_rev[start] == []:
        s_list.append(start)
        dist[start] = 0

for start in s_list:
    dfs(start, -1)

num = 0
for k, v in dist.items():
    num = max(num, v)

print(2 * (n - 1) - num)
0