Test instructions
There is a starting point of 0, the length of the runway, there are n Springboard, for the first springboard, in XI began to take off, but must be in the Xi-pi ~ XI buffer time for PI, and then in TI's time to reach Xi+di, people can go back, but the direction of the springboard is fixed, and then find the shortest time to reach L , and the number of the springboard used to output the sequence of takeoff.
Exercises
The first thing to understand is that the given Xi point is useless, then the useful points are only Xi-pi and Xi + di.
And the transfer situation is complicated, including the situation of the back, including the selection of the springboard, the situation of not choosing a springboard, walking situation, at that time did not think of a good solution, but finally found that this is not the shortest way?
Consider the selection of a springboard, the right and left end of the springboard connected to a one-way edge, the weight of the Pi + ti
Consider the case of not choosing a springboard, a point with all the other points of a two-way edge, the weight of the difference between the distance, but found that there are many sides are useless, so just need to connect the left and right adjacent points.
P.S. The data is too large to be discrete qaq, and SPFA to be stuck, will T in Group 50th, sxbk!
Code:
#include <bits/stdc++.h>using namespace std; #define LL long longconst ll inf = 1e15 + 7;const int N = 1e6 + 7;struct edge {int U, V, NXT, W, id;} E[N<<2];STRUCT Node {int S, T, W;} rd[n];int Inq[n], disc[n<<1], dis[n], dcnt, Head[n], ecnt, N, L, Ans[n], CN T, pre[n];typedef pair <int, int> PII, #define MK (A, B) Make_pair (A, c) priority_queue <pii, Vector <pii>, GRE ater<pii> > Q;void Adde (int u, int v, int w, int id) {e[ecnt].u = U;E[ECNT].V = V;E[ECNT].W = W;e[ecnt].id = ID; E[ECNT].NXT = Head[u];head[u] = ecnt++;} void Dijkstra () {memset (dis, 127, sizeof dis);p re[1] = -1;dis[1] = 0;q.push (MK (0, 1)); while (!q.empty ()) {int u = q.top ( ). Second;q.pop (); Inq[u] = 0;for (int it = head[u]; it =-1; it = e[it].nxt) {int v = e[it].v;if (Dis[v] > Dis[u] + e[it].w) {Dis[v] = d Is[u] + e[it].w;pre[v] = It;q.push (MK (dis[v], V));}}} for (int it = pre[dcnt]; it =-1; it = pre[e[it].u]) if (e[it].id! =-1) ans[++cnt] = e[it].id;} int main () {scanf ("%d%d", &n, &l); Memset (Head,-1, sizeof head);d isc[++dcnt] = 0;disc[++dcnt] = l;for (int i = 1; I <= n; ++i) {int x, D, t , p;scanf ("%d%d%d%d", &x, &d, &t, &p); rd[i].s = x-p;rd[i].t = x + d;rd[i].w = t + p;if (X-p < 0 | | x + D > L) continue;disc[++dcnt] = x-p;disc[++dcnt] = x + D;} Sort (disc + 1, disc + 1 + dcnt);d cnt = unique (disc + 1, disc + 1 + dcnt)-disc-1;for (int i = 1; I <= n; ++i) {if (rd[i].t > L | | rd[i].s < 0) Continue;int s = lower_bound (disc + 1, disc + 1 + dcnt, RD[I].S)-Disc;int t = Lower_ Bound (disc + 1, disc + 1 + dcnt, rd[i].t)-Disc;adde (S, T, RD[I].W, i);} for (int i = 2; I <= dcnt; ++i) {int s = i-1, t = i, W = disc[t]-Disc[s];adde (S, T, W,-1); Adde (T, S, W,-1);} Dijkstra (); cout << dis[dcnt] << endl << cnt << endl;for (int i = cnt; I >= 1; i) printf ("%d ", Ans[i]); return 0;}
Summarize:
Complicated transfer relation, simple restriction condition, can consider graph theory Qaq
Codeforces 141D Take-off Ramps