結果

問題 No.2674 k-Walk on Bipartite
ユーザー rlangevinrlangevin
提出日時 2024-03-19 12:20:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,904 KB
最終ジャッジ日時 2024-03-19 12:20:41
合計ジャッジ時間 6,909 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,608 KB
testcase_01 AC 41 ms
55,608 KB
testcase_02 AC 40 ms
55,608 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 199 ms
94,228 KB
testcase_08 AC 234 ms
91,444 KB
testcase_09 AC 158 ms
91,720 KB
testcase_10 AC 310 ms
93,156 KB
testcase_11 AC 202 ms
90,632 KB
testcase_12 AC 250 ms
90,204 KB
testcase_13 AC 139 ms
89,964 KB
testcase_14 AC 81 ms
85,368 KB
testcase_15 AC 349 ms
96,484 KB
testcase_16 AC 218 ms
94,652 KB
testcase_17 AC 240 ms
90,636 KB
testcase_18 AC 100 ms
84,020 KB
testcase_19 AC 167 ms
92,672 KB
testcase_20 AC 146 ms
91,000 KB
testcase_21 AC 273 ms
92,424 KB
testcase_22 AC 352 ms
98,904 KB
testcase_23 AC 35 ms
53,460 KB
testcase_24 AC 36 ms
53,460 KB
testcase_25 AC 35 ms
53,460 KB
testcase_26 AC 34 ms
53,460 KB
testcase_27 AC 35 ms
53,460 KB
testcase_28 AC 36 ms
53,460 KB
testcase_29 AC 35 ms
53,460 KB
testcase_30 AC 35 ms
53,460 KB
testcase_31 AC 35 ms
53,460 KB
testcase_32 AC 35 ms
53,460 KB
testcase_33 AC 37 ms
53,460 KB
testcase_34 AC 36 ms
53,460 KB
testcase_35 AC 36 ms
53,460 KB
testcase_36 AC 35 ms
53,460 KB
testcase_37 AC 39 ms
53,460 KB
testcase_38 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
G = [[] for i in range(N)]
s, t, k = map(int, input().split())
s, t = s - 1, t - 1
if N == 1:
    print("Yes") if k == 0 else print("No")
    exit()
    
if N == 2:
    if s == t:
        if k % 2:
            print("No")
        else:
            if M == 0:
                if k == 0:
                    print("Yes")
                else:
                    print("Unknown")
            else:
                print("Yes")
    else:
        if k % 2 == 0:
            print("No")
        else:
            if M == 0:
                print("Unknown")
            else:
                print("Yes")
    exit()                   


for i in range(M):
    u, v = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append(v)
    G[v].append(u)
    
from collections import deque
def bfs(G, s):
    Q = deque([s])
    N = len(G)
    dist = [-1] * N
    par = [-1] * N
    dist[s] = 0
    while Q:
        u = Q.popleft()
        for v in G[u]:
            if dist[v] != -1:
                continue
            dist[v] = dist[u] + 1
            par[v] = u
            Q.append(v)

    return dist

D = bfs(G, s)
if D[t] == -1:
    print("Unknown")
elif (D[t] - k) % 2:
    print("No")
elif D[t] <= k:
    print("Yes")
else:
    print("Unknown")
0