結果

問題 No.1190 Points
ユーザー kk
提出日時 2020-09-05 03:15:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 210,988 KB
実行使用メモリ 20,196 KB
最終ジャッジ日時 2023-08-18 02:11:46
合計ジャッジ時間 9,017 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,748 KB
testcase_01 AC 3 ms
5,676 KB
testcase_02 AC 3 ms
5,616 KB
testcase_03 AC 101 ms
15,812 KB
testcase_04 AC 62 ms
14,944 KB
testcase_05 AC 115 ms
13,888 KB
testcase_06 AC 84 ms
18,672 KB
testcase_07 AC 165 ms
19,636 KB
testcase_08 AC 213 ms
20,196 KB
testcase_09 AC 198 ms
18,576 KB
testcase_10 AC 211 ms
19,888 KB
testcase_11 AC 134 ms
15,012 KB
testcase_12 AC 191 ms
19,644 KB
testcase_13 AC 111 ms
13,156 KB
testcase_14 AC 26 ms
13,784 KB
testcase_15 AC 196 ms
19,396 KB
testcase_16 AC 13 ms
8,212 KB
testcase_17 AC 182 ms
18,944 KB
testcase_18 AC 65 ms
9,280 KB
testcase_19 AC 27 ms
16,380 KB
testcase_20 AC 94 ms
11,528 KB
testcase_21 AC 28 ms
11,684 KB
testcase_22 AC 38 ms
17,236 KB
testcase_23 AC 211 ms
19,912 KB
testcase_24 AC 212 ms
19,796 KB
testcase_25 AC 81 ms
19,320 KB
testcase_26 AC 58 ms
19,052 KB
testcase_27 AC 82 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
const int INF = 1e9;

int n, m, p;
int s, g;
vector<int> edges[100000];

vector<vector<int> > calc(int v) {
  vector<vector<int> > dist(n, vector<int>(2, INF));
  queue<pair<int, int> > q;
  q.emplace(v, 0);
  dist[v][0] = 0;
  while (!q.empty()) {
    int u, parity;
    tie(u, parity) = q.front();
    q.pop();
    for (int w: edges[u]) {
      if (dist[w][!parity] == INF) {
        dist[w][!parity] = dist[u][parity] + 1;
        q.emplace(w, !parity);
      }
    }
  }
  return dist;
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  cin >> n >> m >> p;
  cin >> s >> g;
  --s, --g;
  REP (i, m) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  auto d1 = calc(s), d2 = calc(g);
  vector<int> ret;

  REP (k, n) {
    bool ck = false;
    REP (i, 2) REP (j, 2) {
      int d = d1[k][i] + d2[k][j];
      if (d <= p && (p - d) % 2 == 0)
        ck = true;
    }
    if (ck)
      ret.push_back(k);
  }

  if (ret.empty())
    cout << -1 << endl;
  else {
    cout << ret.size() << endl;
    for (auto k: ret)
      cout << (k + 1) << endl;
  }
  
  return 0;
}

0