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 |
谁能看下为什么错吗。。谢谢。。。#include<stdio.h> #include<string.h> #include<algorithm> #define MAX 10000000 using namespace std; int k,a[1005][1005],n,sign[1005][1005],result[10005],r[10005],visit[10005]; int dijk(int value) { int i,j,cost=0,min,vertex,cur; for(i=1;i<=n;i++) { visit[i]=0; for(j=1;j<=n;j++) sign[i][j]=1000; } for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(a[i][j]<MAX) { if(a[i][j]>value) sign[i][j]=1; else if(a[i][j]<=value) sign[i][j]=0; } visit[1]=1; for(i=1;i<=n;i++) result[i]=sign[1][i]; for(i=2;i<=n;i++) { min=10000; for(j=1;j<=n;j++) if(visit[j]==0&&min>result[j]) { min=result[j]; vertex=j; } visit[vertex]=1; for(j=1;j<=n;j++) if(visit[j]==0&&(cur=result[vertex]+sign[vertex][j])<result[j]) result[j]=cur; } //printf("result----%d\n",result[n]); if(result[n]<=k) return 1; else return 0; } int main() { int p,i,j,x,y,c,max,cur,left,right,mid; while(scanf("%d%d%d",&n,&p,&k)!=EOF) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) a[i][j]=MAX; max=0; for(i=0,cur=0;i<p;i++) { scanf("%d%d%d",&x,&y,&c); result[cur++]=c; if(c>max) max=c; a[x][y]=a[y][x]=c; } //printf("%d------cur\n",cur); sort(&result[0],&result[p]); r[0]=0; r[1]=result[0]; for(i=1,cur=2;i<p;i++) if(result[i]!=result[i-1]) r[cur++]=result[i]; /*for(i=0;i<cur;i++) printf("%d----r\n",r[i]);*/ left=0; right=cur-1; while(left<=right) { mid=(left+right)>>1; if(dijk(r[mid])) right=mid-1; else left=mid+1; } printf("%d\n",r[left]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator