HTTP://ACM.CSU.EDU.CN/ONLINEJUDGE/PROBLEM.PHP?ID=1014 (Topic link)
Test instructions
From one point to the other, you can walk, take a bus or play, different modes of transportation spend different money, of course, the time spent is different. The shortest time from the beginning S to the end point T in case the total amount of money spent is less than L.
Solution
Should yzc the invitation to do this problem, is a hierarchical map of the shortest way, transfer a bit disgusting.
Details
Note that initialization, and the bus 22 is not the shortest way to go, but a direct connection between two points of the edge.
Code
codevs1199#include<algorithm> #include <iostream> #include <cstdlib> #include <cstring># include<cstdio> #include <vector> #include <cmath> #include <queue> #define LL long Long#define INF 1000000000#define Pi ACOs ( -1.0) #define FREE (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); using namespace Std;const int maxn=200,maxm=1010,maxw=3010;struct edge {int to,next,w;} e[maxm<<1];struct data {int num,w;}; int Head[maxn],vis[maxn][maxw],t[maxn][maxn],n,m,s,t,b,l,cnt;int DIS[MAXN][MAXW],F[MAXN][MAXN],D[MAXN][MAXN]; vector<int> v[maxn];queue<data> q;void Link (int u,int v,int W) {E[++cnt].to=v;e[cnt].next=head[u];head[u] =cnt;e[cnt].w=w;e[++cnt].to=u;e[cnt].next=head[v];head[v]=cnt;e[cnt].w=w;} void Init () {for (Int. i=1;i<=n;i++) for (int j=1;j<=n;j++) f[i][j]=d[i][j]=inf;for (int i=1;i<=n;i++) f[i][i]= head[i]=0;for (int i=1;i<=n;i++) v[i].clear (); while (!q.empty ()) Q.pop (); cnt=0;} void Floyed () {for (Int. k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j && j!=k && i!=k) f[i][j]=min (f[i][j],f[i][k]+f[k ][J]);} void walk (data x) {for (int i=head[x.num];i;i=e[i].next) if (dis[e[i].to][x.w+e[i].w*3]>dis[x.num][x.w]+e[i].w* {dis[e[i].to][x.w+e[i].w*3]=dis[x.num][x.w]+e[i].w*1000;if (!vis[e[i].to][x.w+e[i].w*3]) {Q.push (data) {E[i ].to,x.w+e[i].w*3}); vis[e[i].to][x.w+e[i].w*3]=1;}}} void bus (data x) {for (int i=0;i< (int) v[x.num].size (); i++) {int s,p=v[x.num][i];for (s=1;s<=t[p][0];s++) if (t[p][ S]==x.num) break;s++;d ouble d=0;for (s;s<=t[p][0];s++) {d+=d[t[p][s-1]][t[p][s]];if (dis[t[p][s]][x.w+6]>dis[ x.num][x.w]+d*250) {dis[t[p][s]][x.w+6]=dis[x.num][x.w]+d*250;if (!vis[t[p][s]][x.w+6]) {Q.push (data) {T[p][s], X.w+6}); vis[t[p][s]][x.w+6]=1;}}}} void Taxi (data x) {for (int i=1;i<=n;i++) if (i!=x.num) {int w=x.w+10+ (f[x.num][i]>3) (f[x.num][i]-3): 0); if (di s[i][w]>dis[x.num][x.w]+f[x.num][i]*125) {dis[i][w]=dis[x.num][x.w]+f[x.num][i]*125;if (!Vis[i][w]) {Q.push (data) {i,w}); vis[i][w]=1;}}} void SPFA (int s) {for (Int. i=1;i<=n;i++) for (int j=0;j<=l;j++) Dis[i][j]=inf;dis[s][0]=0;q.push ((data) {s,0}); while (!q.empty ()) {data X=q.front (); Q.pop (); Vis[x.num][x.w]=0;walk (x); bus (x); taxi (x);}} int main () {int case;scanf ("%d", &case), while (case--) {scanf ("%d%d%d%d%d%d", &l,&n,&m,&s,&t, &B), Init (), for (int uu,vv,ww,i=1;i<=m;i++) {scanf ("%d%d%d", &UU,&VV,&WW), Link (uu,vv,ww);d [uu][ VV]=D[VV][UU]=F[UU][VV]=F[VV][UU]=WW;} for (int. i=1;i<=b;i++) {scanf ("%d", &t[i][0]), for (int j=1;j<=t[i][0];j++) {scanf ("%d", &t[i][j]); V[t[i] [j]]. Push_back (i);}} Floyed (); SPFA (S), int ans=inf;for (int i=0;i<=l;i++) ans=min (Ans,dis[t][i]), if (ans==inf) printf ("no\n"), Else printf ("%d\n", ans);} return 0;}
"Csuoj1014" West Lake three-person line