結果

問題 No.1190 Points
ユーザー MayimgMayimg
提出日時 2020-08-23 20:04:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,325 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 200,336 KB
実行使用メモリ 10,380 KB
最終ジャッジ日時 2024-04-23 18:33:19
合計ジャッジ時間 3,791 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 31 ms
8,488 KB
testcase_04 AC 26 ms
7,808 KB
testcase_05 AC 26 ms
7,420 KB
testcase_06 AC 37 ms
9,728 KB
testcase_07 AC 43 ms
10,232 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 10 ms
6,656 KB
testcase_15 WA -
testcase_16 AC 7 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 9 ms
7,040 KB
testcase_20 WA -
testcase_21 AC 14 ms
6,144 KB
testcase_22 AC 19 ms
7,936 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 37 ms
9,984 KB
testcase_26 AC 33 ms
9,088 KB
testcase_27 AC 36 ms
9,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m, p;
  cin >> n >> m >> p;
  int st, gol;
  cin >> st >> gol;
  st--;
  gol--;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  const int INF = (int) 1e9;
  vector<int> dist_fs(n, INF);
  vector<int> dist_fg(n, INF);
  vector<int> que = {st};
  dist_fs[st] = 0;
  for (int i = 0; i < (int) que.size(); i++) {
    for (int j : g[que[i]]) {
      if (dist_fs[j] != INF) continue;
      dist_fs[j] = dist_fs[que[i]] + 1;
      que.push_back(j);
    }
  }
  que.clear();
  que.push_back(gol);
  dist_fg[gol] = 0;
  for (int i = 0; i < (int) que.size(); i++) {
    for (int j : g[que[i]]) {
      if (dist_fg[j] != INF) continue;
      dist_fg[j] = dist_fg[que[i]] + 1;
      que.push_back(j);
    }
  }
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (dist_fs[i] == INF || dist_fg[i] == INF) continue;
    int d = dist_fg[i] + dist_fs[i];
    if (d > p) continue;
    if ((p - d) % 2 == 0) ans.push_back(i);
  }
  if (ans.empty()) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans.size() << '\n';
  for (auto& x : ans) cout << x + 1 << '\n';
  return 0;
}
0