結果

問題 No.1190 Points
ユーザー MayimgMayimg
提出日時 2020-08-24 20:57:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,543 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 201,124 KB
実行使用メモリ 12,580 KB
最終ジャッジ日時 2024-04-24 03:48:02
合計ジャッジ時間 4,256 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 34 ms
9,116 KB
testcase_04 AC 29 ms
8,192 KB
testcase_05 AC 27 ms
8,060 KB
testcase_06 AC 41 ms
10,300 KB
testcase_07 AC 49 ms
11,128 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 14 ms
7,040 KB
testcase_15 WA -
testcase_16 AC 9 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 9 ms
7,808 KB
testcase_20 WA -
testcase_21 AC 15 ms
6,784 KB
testcase_22 AC 20 ms
8,704 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 44 ms
11,024 KB
testcase_26 AC 36 ms
9,984 KB
testcase_27 AC 42 ms
11,056 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);
  }
  vector<int> dist_s(n << 1, -1);
  vector<int> que = {st << 1};
  dist_s[st << 1] = 0;
  for (int i = 0; i < (int) que.size(); i++) {
    int cur = que[i] >> 1;
    int d = dist_s[que[i]] + 1;
    for (int j : g[cur]) {
      int nxt = (j << 1) + d % 2;
      if (dist_s[nxt] != -1) continue;
      dist_s[nxt] = d;
      que.push_back(nxt);
    }
  }
  vector<int> dist_g(n << 1, -1);
  que = {gol << 1};
  dist_g[gol << 1] = 0;
  for (int i = 0; i < (int) que.size(); i++) {
    int cur = que[i] >> 1;
    int d = dist_g[que[i]] + 1;
    for (int j : g[cur]) {
      int nxt = (j << 1) + d % 2;
      if (dist_g[nxt] != -1) continue;
      dist_g[nxt] = d;
      que.push_back(nxt);
    }
  }
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int c = i << 1;
    for (int u = 0; u < 2; u++) for (int v = 0; v < 2; v++) {
      if (dist_s[c + u] != -1 && dist_g[c + v] != -1 && (u + v) % 2 == p % 2 && dist_s[c + u] + dist_g[c + v] <= p) {
        ans.push_back(i);
        continue;
      }
    }
  }
  if (!ans.empty()) {
    cout << ans.size() << '\n';
    for (auto x : ans) cout << x + 1 << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}
0