結果
| 問題 | No.3463 Beltway |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2026-06-22 16:13:01 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,286 bytes |
| 記録 | |
| コンパイル時間 | 301 ms |
| コンパイル使用メモリ | 85,652 KB |
| 実行使用メモリ | 797,120 KB |
| 最終ジャッジ日時 | 2026-06-22 16:13:21 |
| 合計ジャッジ時間 | 5,424 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 1 RE * 1 MLE * 1 -- * 13 |
ソースコード
import sys
input = sys.stdin.readline
from collections import deque
V,E,S,G=list(map(int,input().split()))
EDGE=[list(map(int,input().split())) for i in range(E)]
for i in range(E):
EDGE[i][0]-=1
EDGE[i][1]-=1
ELIST=[[] for i in range(V)]
ELIST2=[set() for i in range(V)]
for a,b in EDGE:
ELIST[a].append(b)
ELIST[b].append(a)
ELIST2[a].add(b)
ELIST2[b].add(a)
Q=[]
for i in range(V):
if len(ELIST2[i])==1:
Q.append(i)
while Q:
x=Q.pop()
for to in ELIST2[x]:
to2=to
ELIST2[x].remove(to2)
ELIST2[to2].remove(x)
if len(ELIST2[to2])==1:
Q.append(to2)
DP=[[1<<60,0] for i in range(V)]
DP[S-1]=[0,0]
Q=deque()
Q.append(S-1)
while Q:
x=Q.popleft()
now,m=DP[x]
for to in ELIST[x]:
if to in ELIST2[x]:
if DP[to][0]>now+1:
DP[to]=[now+1,m+1]
Q.append(to)
elif DP[to][0]==now and DP[to][1]<m+1:
DP[to]=[now+1,m+1]
Q.append(to)
else:
if DP[to][0]>now+1:
DP[to]=[now+1,m]
Q.append(to)
elif DP[to][0]==now and DP[to][1]<m:
DP[to]=[now+1,m]
Q.append(to)
print(DP[G-1][1])
titia