結果
問題 |
No.1190 Points
|
ユーザー |
|
提出日時 | 2020-08-22 16:15:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 248 ms / 2,000 ms |
コード長 | 1,879 bytes |
コンパイル時間 | 1,870 ms |
コンパイル使用メモリ | 178,304 KB |
実行使用メモリ | 22,472 KB |
最終ジャッジ日時 | 2024-10-15 10:21:34 |
合計ジャッジ時間 | 7,136 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<ll, ll> P; struct edge { ll to, cost; }; const int MAX_V =200000; const ll INF = 1LL<<60; int V; vector<edge> G[MAX_V]; ll d[MAX_V], d0[MAX_V]; void dijkstra(ll s) { // greater<P>を指定することでfirstが小さい順に取り出せるようにする priority_queue<P, vector<P>, greater<P> > que; fill(d, d + V, INF); d[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; rep(i,G[v].size()) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } int main() { int N, M, P, s, g, u, v; cin >> N >> M >> P >> s >> g; V = 2 * N; s--; g--; rep(i, M) { cin >> u >> v; u--; v--; G[u].push_back({v + N, 1}); G[v].push_back({u + N, 1}); G[u + N].push_back({v, 1}); G[v + N].push_back({u, 1}); } dijkstra(s); rep(i, N + N) d0[i] = d[i]; dijkstra(g); vector<int> ans; rep(i, N) { if (P % 2) { ll d1 = d0[i] + d[i + N]; ll d2 = d0[i + N] + d[i]; if (d1 <= P || d2 <= P) ans.push_back(i + 1); } else { ll d1 = d0[i] + d[i]; ll d2 = d0[i + N] + d[i + N]; if (d1 <= P || d2 <= P) ans.push_back(i + 1); } } if (ans.size() == 0) { cout << "-1\n"; return 0; } cout << ans.size() << "\n"; rep(i, ans.size()) cout << ans[i] << "\n"; /* rep(i, N) { cout << d0[i] << " " << d0[i + N] << " " << d[i] << " " << d[i + N] << "\n"; } */ }