1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include <iostream> #include <vector> #include <cstring> #include <queue> #include <cmath>
#define int long long #define endl '\n'
using namespace std;
int n, m, k, r, q; double dis[200009]; vector<pair<int, double>> g[200009];
void dijkstra(int s) { priority_queue<pair<double, int>> pq; pq.push({0, s}); memset(dis, 127, sizeof(dis)); dis[s] = 0; while (!pq.empty()) { int u = pq.top().second; pq.pop(); for (auto [v, w] : g[u]) { if (dis[v] > dis[u] + w) { if (v > n) { dis[v] = ceil(dis[u] + w); } else { dis[v] = dis[u] + w; } pq.push({-dis[v], v}); } } } }
signed main() { freopen("path.in", "rt", stdin); freopen("path.out","wt", stdout); cin >> n >> m >> k >> r >> q; for (int u, v, w, i = 1; i <= m; i++) { cin >> u >> v >> w; g[u].push_back({v, w * 1.0 / r}); g[v].push_back({u, w * 1.0 / r}); } for (int i = 1, t, c; i <= k; i++) { cin >> t >> c; for (int j = 1, x; j <= t; j++) { cin >> x; g[n + i].push_back({x, 0}); g[x].push_back({n + i, c}); } } for (int i = 1, u, v; i <= q; i++) { cin >> u >> v; dijkstra(u); cerr << endl; cout << (int) ceil(dis[v]) << endl; } }
|