結果

問題 No.2674 k-Walk on Bipartite
ユーザー nikoro256nikoro256
提出日時 2024-03-19 15:56:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 1,012 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 99,280 KB
最終ジャッジ日時 2024-03-19 15:56:08
合計ジャッジ時間 7,227 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,604 KB
testcase_01 AC 40 ms
55,604 KB
testcase_02 AC 41 ms
55,604 KB
testcase_03 AC 39 ms
55,604 KB
testcase_04 AC 41 ms
55,604 KB
testcase_05 AC 39 ms
55,604 KB
testcase_06 AC 37 ms
55,604 KB
testcase_07 AC 245 ms
92,940 KB
testcase_08 AC 247 ms
92,504 KB
testcase_09 AC 178 ms
93,120 KB
testcase_10 AC 313 ms
95,996 KB
testcase_11 AC 212 ms
90,656 KB
testcase_12 AC 277 ms
93,316 KB
testcase_13 AC 171 ms
89,464 KB
testcase_14 AC 94 ms
83,216 KB
testcase_15 AC 343 ms
97,392 KB
testcase_16 AC 242 ms
94,772 KB
testcase_17 AC 233 ms
90,420 KB
testcase_18 AC 127 ms
85,084 KB
testcase_19 AC 183 ms
91,524 KB
testcase_20 AC 202 ms
92,404 KB
testcase_21 AC 244 ms
93,340 KB
testcase_22 AC 322 ms
99,280 KB
testcase_23 AC 39 ms
55,604 KB
testcase_24 AC 37 ms
55,604 KB
testcase_25 AC 37 ms
55,604 KB
testcase_26 AC 38 ms
55,604 KB
testcase_27 AC 38 ms
55,604 KB
testcase_28 AC 37 ms
55,604 KB
testcase_29 AC 48 ms
55,604 KB
testcase_30 AC 37 ms
55,604 KB
testcase_31 AC 37 ms
55,604 KB
testcase_32 AC 40 ms
55,604 KB
testcase_33 AC 41 ms
55,604 KB
testcase_34 AC 38 ms
55,604 KB
testcase_35 AC 37 ms
55,604 KB
testcase_36 AC 38 ms
55,604 KB
testcase_37 AC 38 ms
55,604 KB
testcase_38 AC 37 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def bfs(s):
    dq=deque()
    dq.append([s,0])
    high=[10**9 for _ in range(N)]
    high[s]=0
    while 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+1
    return high

N,M=map(int,input().split())
s,t,k=map(int,input().split())
if N==1:
    print('No')
    exit(0)
s-=1
t-=1
edge=[[] 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')
0