結果

問題 No.3326 岩井星人の帰星
コンテスト
ユーザー titia
提出日時 2025-11-05 02:24:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 119,624 KB
最終ジャッジ日時 2025-11-05 02:24:26
合計ジャッジ時間 12,708 ms
ジャッジサーバーID
(参考情報)
judge7 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import deque

N,M=map(int,input().split())

E=[[] for i in range(N+1)]

for i in range(M):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

L=int(input())
DP=[-1]*(N+1)

LIST=[[] for i in range(1001)]

for i in range(L):
    j,k=map(int,input().split())
    LIST[k].append(j)
    DP[j]=k

for i in range(1000,-1,-1):
    for x in LIST[i]:
        if DP[x]>i:
            continue

        for to in E[x]:
            if DP[to]<DP[x]-1:
                DP[to]=DP[x]-1
                LIST[DP[x]-1].append(to)

Q=[1]
OK=[1<<30]*(N+1)
Q=deque(Q)

OK[1]=0
if DP[1]!=-1:
    print("No")
    exit()
    
while Q:
    x=Q.popleft()
    for to in E[x]:
        if DP[to]==-1 and OK[to]>OK[x]+1:
            OK[to]=OK[x]+1
            Q.append(to)

if OK[N]!=1<<30:
    print("Yes")
    print(OK[N])
else:
    print("No")
0