結果
問題 | No.1190 Points |
ユーザー | sten_san |
提出日時 | 2021-02-14 00:16:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,884 bytes |
コンパイル時間 | 2,813 ms |
コンパイル使用メモリ | 219,604 KB |
実行使用メモリ | 24,444 KB |
最終ジャッジ日時 | 2024-07-21 04:19:29 |
合計ジャッジ時間 | 8,073 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 | 67 ms
8,192 KB |
testcase_04 | AC | 38 ms
7,424 KB |
testcase_05 | AC | 84 ms
7,168 KB |
testcase_06 | AC | 38 ms
9,088 KB |
testcase_07 | AC | 103 ms
9,856 KB |
testcase_08 | AC | 165 ms
10,880 KB |
testcase_09 | AC | 166 ms
10,556 KB |
testcase_10 | AC | 168 ms
10,980 KB |
testcase_11 | AC | 120 ms
8,568 KB |
testcase_12 | AC | 155 ms
10,740 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
ソースコード
#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 % 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; } }