結果
問題 | No.2674 k-Walk on Bipartite |
ユーザー |
![]() |
提出日時 | 2024-03-17 03:18:43 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 719 ms / 2,000 ms |
コード長 | 1,255 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 49,792 KB |
最終ジャッジ日時 | 2024-09-30 04:38:01 |
合計ジャッジ時間 | 8,847 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
import sysinput = sys.stdin.readlineN,M=map(int,input().split())s,t,k=map(int,input().split())s-=1t-=1E=[[] for i in range(N)]for i in range(M):u,v=map(int,input().split())u-=1v-=1E[u].append(v)E[v].append(u)DIS=[-1]*NQ=[s]DIS[s]=0LIST=[]while Q:x=Q.pop()LIST.append(x)for to in E[x]:if DIS[to]==-1:DIS[to]=DIS[x]+1Q.append(to)if 0<=DIS[t]<=k and len(LIST)>1:if (DIS[t]-k)%2==0:print("Yes")else:print("No")exit()if DIS[t]>k and len(LIST)>1:if (DIS[t]-k)%2==0:print("Unknown")else:print("No")exit()if DIS[t]==0 and len(LIST)==1:if N==1:if k==0:print("Yes")else:print("No")else:if k==0:print("Yes")elif k%2==0:print("Unknown")else:print("No")exit()DIS2=[-1]*NQ=[t]DIS2[t]=0LIST2=[]while Q:x=Q.pop()LIST2.append(x)for to in E[x]:if DIS2[to]==-1:DIS2[to]=DIS2[x]+1Q.append(to)if len(LIST)==1 and len(LIST2)==1:if k%2==0:print("No")else:print("Unknown")else:print("Unknown")