結果
問題 | No.2674 k-Walk on Bipartite |
ユーザー |
![]() |
提出日時 | 2024-03-19 15:56:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 433 ms / 2,000 ms |
コード長 | 1,012 bytes |
コンパイル時間 | 344 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 99,584 KB |
最終ジャッジ日時 | 2024-09-30 05:33:39 |
合計ジャッジ時間 | 6,833 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
from collections import dequedef bfs(s):dq=deque()dq.append([s,0])high=[10**9 for _ in range(N)]high[s]=0while len(dq)!=0:p,h=dq.popleft()for e in edge[p]:if high[e]==10**9:dq.append([e,h+1])high[e]=h+1return highN,M=map(int,input().split())s,t,k=map(int,input().split())if N==1:print('No')exit(0)s-=1t-=1edge=[[] for _ in range(N)]for _ in range(M):a,b=map(int,input().split())edge[a-1].append(b-1)edge[b-1].append(a-1)dist=bfs(s)if s==t:if k%2==1:print('No')exit(0)elif len(edge[s])==0:print('Unknown')exit(0)else:print('Yes')exit(0)if N==2:if k%2==0:print('No')elif dist[t]==10**9:print('Unknown')else:print('Yes')exit(0)if dist[t]==10**9:print('Unknown')elif dist[t]%2!=k%2:print('No')elif dist[t]<=k:print('Yes')else:print('Unknown')