Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 36654 | Accepted: 10560 |
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
#include<iostream> #include<cstring> #include<cstdio> using namespace std; #define M 10000000 int map[105][105]; int v[105],d[105],p[105]; int n,m; int dj() { int i,j; for(i=1;i<=m;i++) d[i]=map[0][i]; v[0]=1; for(i=1;i<=m;i++) { int min=M,x; for(j=1;j<=m;j++) if(!v[j] && min>d[j]) min=d[x=j]; v[x]=1; for(j=1;j<=m;j++) if(!v[j] && d[j]>d[x]+map[x][j] && map[x][j]>0) d[j]=d[x]+map[x][j]; } return d[1]; } int main() { memset(map,M,sizeof map); memset(v,0,sizeof v); memset(p,0,sizeof p); cin>>n>>m; int i,j,k; int shu,x,pri; for(k=1;k<=m;k++) { cin>>map[0][k]>>p[k]>>shu; for(i=1;i<=shu;i++) { cin>>x>>pri; map[x][k]=pri; } } int minn=M; for(i=1;i<=m;i++) { int pi=p[i]; for(j=1;j<=m;j++) { if(p[j]>pi || pi-p[j]>n) v[j]=1; else v[j]=0; } int mi=dj(); if(minn>mi) minn=mi; } cout<<minn<<endl; return 0; }
原文地址:http://blog.csdn.net/hyccfy/article/details/38434107