結果
| 問題 |
No.2674 k-Walk on Bipartite
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2024-03-15 21:57:32 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 2,000 ms |
| コード長 | 1,612 bytes |
| コンパイル時間 | 2,962 ms |
| コンパイル使用メモリ | 278,360 KB |
| 実行使用メモリ | 13,692 KB |
| 最終ジャッジ日時 | 2024-09-30 01:05:27 |
| 合計ジャッジ時間 | 4,938 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
int solve() {
int n, m;
cin >> n >> m;
int s, t, k;
cin >> s >> t >> k;
s--, t--;
VVI to(n);
rep(_, m) {
int a, b;
cin >> a >> b;
a--, b--;
to[a].emplace_back(b);
to[b].emplace_back(a);
}
if (n == 1) return -1;
VI dist(n, -1);
dist[s] = 0;
queue<int> q;
q.emplace(s);
while (q.size()) {
int u = q.front(); q.pop();
for (int v : to[u]) if (dist[v] == -1) {
dist[v] = dist[u] + 1;
q.emplace(v);
}
}
if (s == t) {
if (k % 2) return -1;
if (to[s].empty()) return 0;
return 1;
}
if (dist[t] == -1) {
if (n == 2 && k % 2 == 0) return -1;
return 0;
}
if (dist[t] % 2 != k % 2) return -1;
if (dist[t] <= k) return 1;
return 0;
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int res = solve();
cout << (res == 1 ? "Yes\n" : res == 0 ? "Unknown\n" : "No\n");
}
Kude