Idea: Build a map!!! Then enumerate the maximum levels and find the shortest path to item 1.
1 2#include <stdio.h>3#include <queue>4#include <string.h>5 #defineMAXN 0X3FFFFFF6 using namespacestd;7typedef pair<int,int>PII;8 intvisit[ the],dis[ the],map[ the][ the],n,m,v,l,p,x,t,vis[ the],liv[ the],sb,w,cas;9priority_queue<pii,vector<pii>,greater<pii> >QQ;Ten intMain () One { A intI,j,max; - while(SCANF ("%d%d",&m,&N)) { - if(n==0&&m==0) the Break; -Memset (LIV,0,sizeof(LIV)); -memset (Map,9,sizeof(map)); -sb=1; +max=0; - intsbsbsb=N; + while(sbsbsb--) A { atscanf"%d%d%d",&p,&l,&x); -map[0][sb]=p; -liv[sb]=l; - if(liv[sb]>max) -max=LIV[SB]; - for(i=1; i<=x;i++) in { -scanf"%d%d",&t,&v); tomap[t][sb]=v; + } -sb++; the } * intmin=MAXN; $ for(i=0; i<=max;i++)Panax Notoginseng { -memset (Visit,0,sizeof(visit)); thememset (DIS,9,sizeof(DIS)); +dis[0]=0; AQq.push (Make_pair (dis[0],0)); the while(!qq.empty ()) + { -PII u=qq.top (); $ Qq.pop (); $ intx=U.second; - if(Visit[x]) - Continue; thevisit[x]=1; - for(j=0; j<=n;j++)Wuyi { the if(liv[j]>= (I-M) &&liv[j]<=i) - { Wu if(Dis[j]> (dis[x]+Map[x][j])) - { Aboutdis[j]=dis[x]+Map[x][j]; $ Qq.push (Make_pair (dis[j],j)); - } - } - } A } + if(dis[1]<min) themin=dis[1]; - } $printf"%d\n", min); the } the return 0; the}Standard Process
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<iomanip>#include<climits>#include<string.h>#include<cmath>#include<stdlib.h>#include<vector>#include<Set>#defineINF 1e7#defineMAXN 100010#defineMAXN 111#defineMAXM 1000#defineMod 1000007#defineMIN (A < b) (A:B)#defineMAX (A > B) (A:B)#defineMem (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong LongLL;intN, M, p, L, X;intg[111][111], price[111], level[111];intvis[111], dis[111];intans, K, T, V;voidinit () {memset (Price,0,sizeof(price)); Memset (Level,0,sizeof(level)); for(inti =0; I <= m; ++i) for(intj =0; J <= M; ++j) {G[i][j]=INF; }}intDijkstra () {intpos, min; for(inti =1; I <= m; ++i) Dis[i] =Price[i]; for(inti =1; I <= m; ++i) {min=INF; for(intj =1; J <= M; ++j) {if(!vis[j] && min >Dis[j]) {POS=J; Min=Dis[j]; }} Vis[pos]=1; for(intj =1; J <= M; ++j)if(!vis[j] && Dis[pos] + G[pos][j] <Dis[j]) dis[j]= Dis[pos] +G[pos][j]; } returnAns = MIN (ans,dis[1]);}voiddeal () {ans=INF; for(inti =1; I <= m; ++i) {intTMP =Level[i]; for(intj =1; J <= M; ++j) {if(Level[j]-tmp > N | | tmp > LEVEL[J]) vis[j] =1; ElseVIS[J] =0; } Dijkstra (); } printf ("%d\n", ans);}voidRead () { for(inti =1; I <= m; ++i) {scanf ("%d%d%d", &price[i], &level[i], &k); for(intj =0; J < K; ++j) {scanf ("%d%d", &t, &v); G[t][i]=v; } }}voidrun () {init (); Read (); Deal ();}intMain () { while(~SCANF ("%d%d", &n, &m), n+m) run (); return 0;}
Nyoj expensive dowry (Dijkstra)