A simple shortest-circuit ...
I went to the topic sample for a long time, the original 12345 those goals are said which road ah, pit ... Note that the weight here is not the edge of the point, the initial cost is accidentally written wrong, with the optimization of the DIJ should be faster ... I'm so tired.
Code:
#include <iostream> #include <cstring> #include <cstdio> #include <map> #include <cstring > #include <algorithm> #define INF 0x3f3f3f3f#define Mem (A, B) memset (A,b,sizeof (a)) using namespace Std;typedef Long long ll;typedef unsigned long long llu;const int Maxn=2000+10;bool vis[maxn];int lowcost[maxn],cost[maxn][maxn];int n,m;struct node{int l,r,w;} pp[maxn];void dij (int beg) {for (int i=0; i<n; ++i) {lowcost[i]=inf; Vis[i]=false; } lowcost[beg]=0; for (int j=0; j<n; ++j) {int k=-1; int _min=inf; for (int i=0; i<n; ++i) if (!vis[i] && lowcost[i]<_min) {_min=lowcost[i ]; K=i; } if (k==-1) break; Vis[k]=true; for (int i=0; i<n; ++i) if (!vis[i] && lowcost[k]+cost[k][i]<lowcost[i]) { Lowcost[i]=lowcost[k]+cost[k][i]; }}}int Main () {freopen ("1.txt"," R ", stdin); int Kase; scanf ("%d", &kase); while (kase--) {scanf ("%d%d", &n,&m); MEM (Cost,inf); for (int i=0; i<n; ++i) {scanf ("%d%d%d", &PP[I].L,&PP[I].R,&PP[I].W); } for (int i=0, i<n; ++i) {for (int j=i+1; j<n; ++j) if (PP[I].R<=PP[J].R & amp;& pp[i].r>=pp[j].l) COST[I][J]=PP[J].W; } dij (0); for (int i=0; i<m; ++i) {int x; scanf ("%d", &x); if (lowcost[x-1]!=inf) printf ("%d\n", LOWCOST[X-1]+PP[0].W); else printf ("%d\n",-1); }} return 0;}
hdu--2851 (Shortest way)