結果

問題 No.1190 Points
ユーザー SSRSSSRS
提出日時 2020-08-22 14:14:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,551 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 173,364 KB
実行使用メモリ 21,692 KB
最終ジャッジ日時 2024-04-23 08:36:32
合計ジャッジ時間 8,054 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 141 ms
16,708 KB
testcase_04 AC 97 ms
15,104 KB
testcase_05 AC 145 ms
13,940 KB
testcase_06 AC 131 ms
20,236 KB
testcase_07 AC 215 ms
21,312 KB
testcase_08 AC 246 ms
21,684 KB
testcase_09 AC 242 ms
19,804 KB
testcase_10 AC 254 ms
21,692 KB
testcase_11 AC 167 ms
15,240 KB
testcase_12 AC 238 ms
21,316 KB
testcase_13 AC 147 ms
13,184 KB
testcase_14 WA -
testcase_15 AC 249 ms
20,368 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 136 ms
11,264 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 256 ms
20,860 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int INF = 100000000;
int main(){
  int N, M, P;
  cin >> N >> M >> P;
  int S, G;
  cin >> S >> G;
  S--;
  G--;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  vector<vector<int>> E2(N * 2);
  for (int i = 0; i < N; i++){
    for (int j : E[i]){
      E2[i * 2].push_back(j * 2 + 1);
      E2[i * 2 + 1].push_back(j * 2);
    }
  }
  vector<int> d1(N * 2, INF);
  d1[S * 2] = 0;
  queue<int> Q1;
  Q1.push(S * 2);
  while (!Q1.empty()){
    int v = Q1.front();
    Q1.pop();
    for (int w : E2[v]){
      if (d1[w] == INF){
        d1[w] = d1[v] + 1;
        Q1.push(w);
      }
    }
  }
  vector<int> d2(N * 2, INF);
  d2[G * 2] = 0;
  queue<int> Q2;
  Q2.push(G * 2);
  while (!Q2.empty()){
    int v = Q2.front();
    Q2.pop();
    for (int w : E2[v]){
      if (d2[w] == INF){
        d2[w] = d2[v] + 1;
        Q2.push(w);
      }
    }
  }
  if (d1[G * 2 + P % 2] > P){
    cout << -1 << endl;
  } else {
    vector<int> ans;
    for (int i = 0; i < N; i++){
      if (P % 2 == 0){
        if (min(d1[i * 2] + d2[i * 2], d1[i * 2 + 1] + d2[i * 2 + 1]) <= P){
          ans.push_back(i);
        }
      }
      if (P % 2 == 1){
        if (min(d1[i * 2 + 1] + d2[i * 2], d1[i * 2] + d2[i * 2 + 1]) <= P){
          ans.push_back(i);
        }
      }
    }
    int K = ans.size();
    cout << K << endl;
    for (int i = 0; i < K; i++){
      cout << ans[i] + 1 << endl;
    }
  }
}
0