这是个WA的程序。。。有待填坑。。。不过我也没看出来哪里错了。。。这只是个草稿。。。
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
#define sc scanf("%d%d",&c,&r)
#define rep(i,c) for (int i=1;i<=c;i++)
const int inf=1e9+7;
const int N=1005;
int h[N][N],g[N][N],c,r,s,e,maxt,d[N];
int x,y,z,k;
int L,R,mid;
int ansh,ansd;
int test;
//dij的时候s和e!!
bool check(){
int hei=mid,now,dist;
bool vis[N];
memset(vis,1,sizeof vis);
memset(d,10,sizeof d);
d[s]=0;
rep(i,c-1){
now=0;dist=inf;
rep(j,c) if (dist>d[j] && vis[j]) now=j,dist=d[j];
vis[now]=0;
rep(j,c) if (h[now][j]>=hei) d[j]=min(d[j],d[now]+g[now][j]);
}
return d[now]!=168430090;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("2692.in","r",stdin);
freopen("2692.out","w",stdout);
#endif
test=0;
for (sc;c && r;sc){
memset(g,10,sizeof g);
memset(h,0,sizeof h);
if (test) printf("\n");
maxt=0;test++;
rep(i,r){
scanf("%d%d%d%d",&x,&y,&k,&z);
g[x][y]=g[y][x]=z;
k==-1 ? h[x][y]=h[y][x]=inf : h[x][y]=h[y][x]=k;
}
scanf("%d%d%d",&s,&e,&maxt);
L=0;R=maxt;ansd=168430090;
for (mid=(L+R)>>1;L<=R;mid=(L+R)>>1)
if (check())
ansh=mid,ansd=d[e],L=mid+1;
else R=mid-1;
printf("Case %d:\n",test);
if (ansd==168430090)
printf("cannot reach destination\n");
else {
printf("maximum height = %d\n",ansh);
printf("length of shortest route = %d\n",ansd);
}
}
return 0;
}