結果
問題 | No.1190 Points |
ユーザー | sten_san |
提出日時 | 2021-02-14 00:49:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 174 ms / 2,000 ms |
コード長 | 3,924 bytes |
コンパイル時間 | 3,304 ms |
コンパイル使用メモリ | 219,232 KB |
実行使用メモリ | 23,284 KB |
最終ジャッジ日時 | 2024-07-21 04:57:11 |
合計ジャッジ時間 | 7,382 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 68 ms
8,192 KB |
testcase_04 | AC | 39 ms
7,296 KB |
testcase_05 | AC | 87 ms
7,168 KB |
testcase_06 | AC | 40 ms
9,088 KB |
testcase_07 | AC | 113 ms
9,728 KB |
testcase_08 | AC | 167 ms
10,880 KB |
testcase_09 | AC | 169 ms
10,428 KB |
testcase_10 | AC | 164 ms
10,752 KB |
testcase_11 | AC | 124 ms
8,656 KB |
testcase_12 | AC | 161 ms
10,752 KB |
testcase_13 | AC | 107 ms
8,568 KB |
testcase_14 | AC | 39 ms
10,500 KB |
testcase_15 | AC | 173 ms
11,388 KB |
testcase_16 | AC | 19 ms
5,828 KB |
testcase_17 | AC | 156 ms
11,004 KB |
testcase_18 | AC | 88 ms
9,268 KB |
testcase_19 | AC | 25 ms
9,768 KB |
testcase_20 | AC | 105 ms
9,364 KB |
testcase_21 | AC | 43 ms
10,580 KB |
testcase_22 | AC | 76 ms
15,136 KB |
testcase_23 | AC | 173 ms
11,604 KB |
testcase_24 | AC | 174 ms
11,488 KB |
testcase_25 | AC | 126 ms
19,104 KB |
testcase_26 | AC | 170 ms
23,284 KB |
testcase_27 | AC | 130 ms
19,228 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } } iofast; struct uns_t {} uns; template <typename Element, typename Head, typename ...Args> auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template <typename Element, typename Head, typename ...Args> auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template <typename T> using pqueue = priority_queue<T, vector<T>, greater<T>>; int main() { constexpr int inf = INT_MAX / 4; int n, m, p; cin >> n >> m >> p; int start, goal; cin >> start >> goal; --start; --goal; auto g = vec<int>(uns, n, 0); 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); } auto bfs = [&](int s) { auto dist = vec<int>(-1, n); queue<int> que; dist[s] = 0; que.push(s); while (!que.empty()) { int c = que.front(); que.pop(); for (auto v : g[c]) { if (0 <= dist[v]) continue; dist[v] = dist[c] + 1; que.push(v); } } return dist; }; auto dist1_s = bfs(start); auto dist1_g = bfs(goal); auto start_s = vec<tuple<int, int>>(uns, 0); auto start_g = vec<tuple<int, int>>(uns, 0); for (int u = 0; u < n; ++u) { for (auto v : g[u]) { if (dist1_s[u] == dist1_s[v]) { start_s.emplace_back(dist1_s[v] + 1, u); start_s.emplace_back(dist1_s[v] + 1, v); } if (dist1_g[u] == dist1_g[v]) { start_g.emplace_back(dist1_g[v] + 1, u); start_g.emplace_back(dist1_g[v] + 1, v); } } } if (size(start_s) == 0 && size(start_g) == 0) { auto ans = vec<int>(uns, 0); for (int i = 0; i < n; ++i) { auto d = dist1_s[i] + dist1_g[i]; if (d <= p && d % 2 == p % 2) { ans.push_back(i + 1); } } if (size(ans) != 0) { cout << size(ans) << endl; for (auto e : ans) { cout << e << endl; } } else { cout << -1 << endl; } return 0; } auto dijkstra = [&](auto &&vtxs) { auto dist = vec<int>(inf, n); pqueue<tuple<int, int>> que; for (auto [c, v] : vtxs) { dist[v] = min(dist[v], c); que.push({ c, v }); } while (!que.empty()) { auto [_, u] = que.top(); que.pop(); for (auto v : g[u]) { if (dist[v] <= dist[u] + 1) continue; dist[v] = dist[u] + 1; que.push({ dist[v], v }); } } return dist; }; auto dist2_s = dijkstra(start_s); auto dist2_g = dijkstra(start_g); auto ans = vec<int>(uns, 0); for (int i = 0; i < n; ++i) { auto d1 = dist1_s[i]; auto d2 = dist2_s[i]; auto d3 = dist1_g[i]; auto d4 = dist2_g[i]; if (d1 < 0 || d3 < 0) continue; if (d1 % 2 == 1) { swap(d1, d2); } if (d3 % 2 == 1) { swap(d3, d4); } if (p % 2 == 0) { if (d1 + d3 <= p || d2 + d4 <= p) { ans.push_back(i + 1); } } else { if (d1 + d4 <= p || d2 + d3 <= p) { ans.push_back(i + 1); } } } if (size(ans) != 0) { cout << size(ans) << endl; for (auto e : ans) { cout << e << endl; } } else { cout << -1 << endl; } }