結果

問題 No.1190 Points
ユーザー 0w10w1
提出日時 2020-11-17 15:59:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 1,613 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 211,884 KB
実行使用メモリ 23,364 KB
最終ジャッジ日時 2023-09-30 14:17:26
合計ジャッジ時間 8,856 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 99 ms
16,464 KB
testcase_04 AC 81 ms
14,852 KB
testcase_05 AC 75 ms
13,824 KB
testcase_06 AC 135 ms
19,868 KB
testcase_07 AC 140 ms
21,124 KB
testcase_08 AC 148 ms
20,972 KB
testcase_09 AC 180 ms
21,392 KB
testcase_10 AC 157 ms
21,068 KB
testcase_11 AC 131 ms
16,916 KB
testcase_12 AC 167 ms
21,176 KB
testcase_13 AC 139 ms
16,044 KB
testcase_14 AC 20 ms
11,112 KB
testcase_15 AC 243 ms
23,040 KB
testcase_16 AC 19 ms
6,608 KB
testcase_17 AC 207 ms
21,392 KB
testcase_18 AC 83 ms
13,820 KB
testcase_19 AC 16 ms
12,232 KB
testcase_20 AC 127 ms
15,784 KB
testcase_21 AC 44 ms
10,648 KB
testcase_22 AC 37 ms
15,332 KB
testcase_23 AC 248 ms
23,364 KB
testcase_24 AC 243 ms
23,184 KB
testcase_25 AC 157 ms
23,176 KB
testcase_26 AC 83 ms
21,448 KB
testcase_27 AC 154 ms
23,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T, T INF>
vector<T> dijkstra(const vector<vector<pair<T, int>>> &g, int st = 0) {
  const int n = g.size();
  vector<T> dis(n, INF); {
    set<pair<T, int>> bag;
    bag.emplace(dis[st] = 0, st);
    while (bag.size()) {
      auto [d, u] = *bag.begin();
      bag.erase(bag.begin());
      if (d != dis[u]) continue;
      for (auto [w, v] : g[u]) {
        if (d + w < dis[v]) {
          bag.emplace(dis[v] = d + w, v);
        }
      }
    }
  }
  return dis;
}

int main() {
  ios::sync_with_stdio(false);

  int N, M, P; { cin >> N >> M >> P; }
  int S, G; { cin >> S >> G; --S, --G; }
  vector<vector<pair<int64_t, int>>> graph(2 * N); {
    for (int i = 0; i < M; ++i) {
      int U, V; { cin >> U >> V; --U, --V; }
      for (int p = 0; p < 2; ++p) {
        graph[U << 1 | p].emplace_back(1, V << 1 | !p);
        graph[V << 1 | p].emplace_back(1, U << 1 | !p);
      }
    }
  }

  vector<int> res; {
    const int64_t INF = (int64_t) 1 << 60;
    vector<int64_t> sdis = dijkstra<int64_t, INF>(graph, S << 1);
    vector<int64_t> gdis = dijkstra<int64_t, INF>(graph, G << 1);
    for (int t = 0; t < N; ++t) {
      for (int p = 0; p < 2; ++p) {
        int64_t sd, gd;
        if ((sd = sdis[t << 1 | p]) == INF) continue;
        if ((gd = gdis[t << 1 | (p ^ P & 1)]) == INF) continue;
        if (sd + gd > P) continue;
        res.push_back(t);
        break;
      }
    }
  }

  if (res.size()) {
    cout << res.size() << endl;
    for (int i = 0; i < res.size(); ++i) cout << res[i] + 1 << "\n";
  } else cout << -1 << endl;
}

0