結果

問題 No.3463 Beltway
コンテスト
ユーザー kidodesu
提出日時 2026-02-28 14:24:45
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 941 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 219 ms
コンパイル使用メモリ 78,036 KB
実行使用メモリ 112,108 KB
最終ジャッジ日時 2026-02-28 15:51:15
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge7 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n, m, s, t = list(map(int, input().split()))
s, t = s-1, t-1
node = [[] for _ in range(n)]
V = [0] * n
E = [1] * m
for _ in range(m):
    u, v = list(map(lambda x: int(x)-1, input().split()))
    node[u].append((v, _))
    node[v].append((u, _))
    V[u] += 1
    V[v] += 1

S = [i for i in range(n) if V[i] == 1]
while S:
    now = S.pop()
    for nxt, idx in node[now]:
        if not E[idx]:
            continue
        E[idx] = 0
        V[now] -= 1
        V[nxt] -= 1
        if V[nxt] == 1:
            S.append(nxt)

D = [-1 for _ in range(n)]
F = [-1] * n
B = [s]
D[s] = 0
F[s] = 0
while A := B:
    B = []
    for now in A:
        cnt = F[now]
        for nxt, idx in node[now]:
            ncnt = cnt + E[idx]
            if D[nxt] == -1:
                D[nxt] = D[now] + 1
                B.append(nxt)
                F[nxt] = ncnt
            elif D[nxt] == D[now] + 1:
                F[nxt] = max(F[nxt], ncnt)
print(F[t])
0