結果

問題 No.2674 k-Walk on Bipartite
ユーザー 👑 nu50218nu50218
提出日時 2024-03-14 14:59:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 464 ms / 2,000 ms
コード長 1,868 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 99,020 KB
最終ジャッジ日時 2024-03-14 15:00:00
合計ジャッジ時間 8,606 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,604 KB
testcase_01 AC 40 ms
55,604 KB
testcase_02 AC 40 ms
55,604 KB
testcase_03 AC 39 ms
55,604 KB
testcase_04 AC 39 ms
55,604 KB
testcase_05 AC 51 ms
55,604 KB
testcase_06 AC 41 ms
55,604 KB
testcase_07 AC 245 ms
94,224 KB
testcase_08 AC 331 ms
90,712 KB
testcase_09 AC 210 ms
94,524 KB
testcase_10 AC 382 ms
93,944 KB
testcase_11 AC 271 ms
90,540 KB
testcase_12 AC 392 ms
92,416 KB
testcase_13 AC 192 ms
90,744 KB
testcase_14 AC 114 ms
84,364 KB
testcase_15 AC 416 ms
96,496 KB
testcase_16 AC 325 ms
95,920 KB
testcase_17 AC 317 ms
90,416 KB
testcase_18 AC 146 ms
85,980 KB
testcase_19 AC 222 ms
92,672 KB
testcase_20 AC 234 ms
93,812 KB
testcase_21 AC 310 ms
91,816 KB
testcase_22 AC 464 ms
99,020 KB
testcase_23 AC 40 ms
55,604 KB
testcase_24 AC 40 ms
55,604 KB
testcase_25 AC 40 ms
55,604 KB
testcase_26 AC 40 ms
55,604 KB
testcase_27 AC 40 ms
55,604 KB
testcase_28 AC 40 ms
55,604 KB
testcase_29 AC 44 ms
55,604 KB
testcase_30 AC 40 ms
55,604 KB
testcase_31 AC 40 ms
55,604 KB
testcase_32 AC 40 ms
55,604 KB
testcase_33 AC 43 ms
55,604 KB
testcase_34 AC 41 ms
55,604 KB
testcase_35 AC 40 ms
55,604 KB
testcase_36 AC 40 ms
55,604 KB
testcase_37 AC 40 ms
55,604 KB
testcase_38 AC 40 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/pypy3
from collections import deque

Yes = "Yes"
Unknown = "Unknown"
No = "No"

def main():
    # 入力受取
    N, M = map(int, input().split())
    s, t, k = map(int, input().split())
    s -= 1
    t -= 1

    adj = [[] for _ in range(N)]
    for i in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        adj[u].append((v))
        adj[v].append((u))

    # BFS
    que = deque()
    dist = [0] * N
    visited = [False] * N

    que.append(s)
    dist[s] = 0
    visited[s] = True

    while len(que) != 0:
        v = que.popleft()

        for u in adj[v]:
            if not visited[u]:
                que.append(u)
                dist[u] = dist[v] + 1
                visited[u] = True

    # グラフ(V, F)に長さkの歩道が存在する
    if visited[t] and dist[t] <= k and dist[t] % 2 == k % 2 and len(adj[s]) != 0:
        print(Yes)
        return

    # グラフ(V, F)に長さkの歩道が存在しない

    # sとtが連結
    if visited[t]:
        # 最短経路長がkの偶奇と一致しない
        if dist[t] % 2 != k % 2:
            print("No")
            return

        # 最短経路長がkの偶奇と一致する
        # s == tのとき、N = 1かで判定
        if s == t:
            print(Unknown if N != 1 else No)
            return

        # s != tのとき、最短経路長を 1 または 2 にできる
        min_dist = (1 if k % 2 else 2)
        print(Unknown if min_dist <= k else No)
        return

    # sとtが非連結
    # N = 2 かつ k%2 == 0 のとき別処理
    if N == 2 and k % 2 == 0:
        print(No)
        return

    # それ以外のとき、最短経路長を 1 または 2 の好きな方にできる
    min_dist = (1 if k % 2 else 2)
    print(Unknown if min_dist <= k else No)
    return

if __name__ == "__main__":
    main()
0