結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
63,028 KB
testcase_01 AC 38 ms
54,528 KB
testcase_02 AC 39 ms
54,660 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(int)
for start in visited:
    if g_rev[start] == []:
        s_list.append(start)
        dist[start] = 0

#print(s_list)
#print(g)

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

#print(dist)

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

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