結果
問題 | No.2674 k-Walk on Bipartite |
ユーザー |
![]() |
提出日時 | 2024-04-26 13:51:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 1,204 bytes |
コンパイル時間 | 639 ms |
コンパイル使用メモリ | 58,616 KB |
実行使用メモリ | 13,676 KB |
最終ジャッジ日時 | 2024-11-14 02:00:05 |
合計ジャッジ時間 | 3,325 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
/* -*- coding: utf-8 -*-** 2674.cc: No.2674 k-Walk on Bipartite - yukicoder*/#include<cstdio>#include<vector>#include<queue>#include<algorithm>using namespace std;/* constant */const int MAX_N = 200000;/* typedef */typedef vector<int> vi;typedef queue<int> qi;/* global variables */vi nbrs[MAX_N];int ds[MAX_N];/* subroutines *//* main */int main() {int n, m, s, t, k;scanf("%d%d%d%d%d", &n, &m, &s, &t, &k);s--, t--;for (int i = 0; i < m; i++) {int u, v;scanf("%d%d", &u, &v);u--, v--;nbrs[u].push_back(v);nbrs[v].push_back(u);}fill(ds, ds + n, -1);ds[s] = 0;qi q;q.push(s);int sz = 1;while (! q.empty()) {int u = q.front(); q.pop();for (auto v: nbrs[u])if (ds[v] < 0) {ds[v] = ds[u] + 1, sz++;q.push(v);}}if (ds[t] >= 0) {if ((k - ds[t]) & 1) puts("No");else if (s == t) {if (sz > 1) puts("Yes");else if (n == 1) puts("No");else puts("Unknown");}else {if (s != t && ds[t] <= k) puts("Yes");else puts("Unknown");}}else {if (n == 2 && ! (k & 1)) puts("No");else puts("Unknown");}return 0;}