标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 45892 | Accepted: 13614 |
Description
Input
Output
Sample Input
1 4 10000 3 2 2 8000 3 5000 1000 2 1 4 200 3000 2 1 4 200 50 2 0
Sample Output
5250
Source
// // main.cpp // poj1062 // // Created by Candy on 9/13/16. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cstring> using namespace std; const int N=105,INF=1e9; inline int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} return x; } int m,n,l[N],sl[N],p,t,x,val,ans=INF; struct edge{ int v,w,ne; }e[N*N]; int h[N],cnt=0; inline void ins(int u,int v,int w){ cnt++; e[cnt].v=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=cnt; } int d[N],inq[N],q[N*N],head=1,tail=0; void spfa(int mn){ for(int i=1;i<=n;i++) d[i]=INF; d[0]=0; inq[0]=1; q[++tail]=0; while(head<=tail){ int u=q[head++];inq[u]=0; for(int i=h[u];i;i=e[i].ne){ int v=e[i].v,w=e[i].w; if(mn+m<l[v]||l[v]<mn) continue;//{printf("v %d\n",v);continue;} if(d[v]>d[u]+w){ d[v]=d[u]+w; if(!inq[v]){inq[v]=1;q[++tail]=v;} } } } ans=min(ans,d[1]); } int main(int argc, const char * argv[]) { m=read();n=read(); for(int i=1;i<=n;i++){ p=read();l[i]=sl[i]=read();x=read(); ins(0,i,p); while(x--){t=read();val=read();ins(t,i,val);} } sort(sl+1,sl+1+n); for(int i=1;i<=n;i++) if(sl[i]<=l[1]) spfa(sl[i]); printf("%d",ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/candy99/p/5870228.html