結果

問題 No.3291 K-step Navigation
ユーザー Kyutatsu
提出日時 2025-10-03 23:20:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,686 bytes
コンパイル時間 5,355 ms
コンパイル使用メモリ 334,932 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-03 23:20:22
合計ジャッジ時間 7,210 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using ll = long long;

int main() {
    // s-t みたいな時、Kが奇数なら行き来するだけでいい??
    // K=2nかつs, t が孤立してる時だけ無理?
    ll N, M, K, s, t; cin >> N >> M >> K >> s >> t;
    s--;
    t--;
    vector<int> U(M), V(M);
    vector E(N, vector<int>());
    for (int i=0;i<M;i++) {
        cin >> U[i] >> V[i];
        U[i]--;
        V[i]--;
        E[U[i]].push_back(V[i]);
        E[V[i]].push_back(U[i]);
    }
    vector<int> dist_s(N, 1e9);
    vector<int> dist_t(N, 1e9);
    queue<int> qs;
    queue<int> qt;

    dist_s[s] = 0;
    qs.push(s);
    while(!qs.empty()) {
        int c = qs.front(); qs.pop();
        for (auto nx: E[c]) {
            int cost = dist_s[c] + 1;
            if (cost < dist_s[nx]) {
                qs.push(nx);
                dist_s[nx] = cost;
            }
        }
    }
    dist_t[t] = 0;
    qt.push(t);
    while(!qt.empty()) {
        int c = qt.front(); qt.pop();
        for (auto nx: E[c]) {
            int cost = dist_t[c] + 1;
            if (cost < dist_t[nx]) {
                qt.push(nx);
                dist_t[nx] = cost;
            }
        }
    }

    for (int i=0;i<N;i++) {
        int tmp = dist_s[i]+dist_t[i];
        if (tmp == K) {
            cout << "Yes"  << endl;
            return 0;
        }
    }
    for (int i=0;i<N;i++) {
        for (int j=0;j<N;j++) {
            int tmp = dist_s[i]+dist_t[j]+1;
            if (tmp == K || tmp == K-1) {
                cout << "Yes"  << endl;
                return 0;
            }
        }
    }


    cout << "No" << endl;
    return 0;
}
0