結果
問題 |
No.2674 k-Walk on Bipartite
|
ユーザー |
|
提出日時 | 2025-03-19 00:47:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 2,092 bytes |
コンパイル時間 | 2,100 ms |
コンパイル使用メモリ | 204,216 KB |
実行使用メモリ | 13,656 KB |
最終ジャッジ日時 | 2025-03-19 00:47:13 |
合計ジャッジ時間 | 4,444 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename Ostream, typename Cont> typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(Ostream& os, const Cont& v){ os << "[ "; for(auto &x : v) os << x << ' '; return os << "]"; } template<typename Ostream, typename ...Ts> Ostream& operator << (Ostream &os, const pair<Ts...> &p){ return os << "{" << p.first << ", " << p.second << "}"; } void dbg_cerr() { cerr << "\e[0m\n"; } template<typename Head, typename... Tail> void dbg_cerr(Head H, Tail... T) { cerr << ' ' << H; dbg_cerr(T...); } #ifdef LTF #define DEBUG(...) cerr << "\e[1;31m[" #__VA_ARGS__ "]:", dbg_cerr(__VA_ARGS__) #else #define DEBUG(...) #endif void Solve() { int N, M; cin >> N >> M; int s, t, k; cin >> s >> t >> k; s--, t--; vector g(N, vector<int>()); for (int i = 0; i < M; i++) { int x, y; cin >> x >> y; x--, y--; g[x].push_back(y), g[y].push_back(x); } if (N == 1) { assert(s == t); if (k == 0) cout << "Yes\n"; else cout << "No\n"; return; } vector<int> dis(N, -1); queue<int> q; dis[s] = 0, q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) { if (dis[v] == -1) { dis[v] = dis[u] + 1; q.push(v); } } } DEBUG(dis[t]); if (dis[t] == -1) { if (N == 2 && (k % 2 == 0)) { cout << "No\n"; } else { cout << "Unknown\n"; } } else { if ((dis[t] ^ k) & 1) { // dis and k have different parity cout << "No\n"; } else { if (s == t) { if (k == 0) cout << "Yes\n"; else { bool flag = true; for (int u = 0; u < N; u++) { if (u != s) flag &= (dis[u] == -1); } if (flag) cout << "Unknown\n"; else cout << "Yes\n"; } } else { if (dis[t] <= k) cout << "Yes\n"; else cout << "Unknown\n"; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) { Solve(); } return 0; }