Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
floyd求最短路加一下限制过的#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> using namespace std; int n,m,p,l0,x,lmin[300][300],lmax[300][300],f[300][300],l[300],t,v; int main() { scanf("%d%d",&m,&n); memset(f,-1,sizeof(f)); for(int i=1;i<=n;i++) { scanf("%d%d%d",&p,&l0,&x); f[n+i][i]=p;l[i]=l0;l[n+i]=l0; for(int j=1;j<=x;j++) { scanf("%d%d",&t,&v); f[t][i]=v; } } n=2*n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(f[i][j]!=-1) { lmin[i][j]=l[i]<l[j]?l[i]:l[j]; lmax[i][j]=l[i]>l[j]?l[i]:l[j]; } for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(f[i][k]!=-1 && f[k][j]!=-1 && abs(lmin[i][k]-lmin[k][j])<=m && abs(lmax[i][k]-lmax[k][j])<=m && abs(lmin[i][k]-lmax[k][j])<=m && abs(lmax[i][k]-lmin[k][j])<=m ) if(f[i][k]+f[k][j]<f[i][j] || f[i][j]==-1) { f[i][j]=f[i][k]+f[k][j]; lmin[i][j]=lmin[i][k]<lmin[k][j]?lmin[i][k]:lmin[k][j]; lmax[i][j]=lmax[i][k]>lmax[k][j]?lmax[i][k]:lmax[k][j]; } int minn=1<<30; for(int i=n/2+1;i<=n;i++) if(f[i][1]!=-1 && f[i][1]<minn)minn=f[i][1]; printf("%d\n",minn); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator