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 |
找到2点半了还不知道为啥WA..网上的测试数据都能过,为什么还是WA...请教高手#include<iostream> using namespace std; #define MAX_INT 21394453 void Dijkstra(long s,long n,long *dist) ; long map[1301][1301],lo[1300]; int main() { long dis[1200],m,n,cla[1200],a,b,c,i,j,k,min,up,down; cin>>m>>n; for(i=1;i<=n;i++) for(j=1;j<=n;j++) map[i][j]=MAX_INT; for(i=1;i<=n;i++) { cin>>map[i][n+1]>>cla[i]>>a; map[n+1][i]=map[i][n+1]; for(k=1;k<=a;k++) { cin>>b>>c; map[i][b]=c; map[b][i]=c; } } min=MAX_INT; for(k=0;k<=m;k++) { up=cla[1]+k; down=cla[1]-m+k; for(i=1;i<=n+1;i++) lo[i]=1; for(i=2;i<=n;i++) if(cla[i]<down||cla[i]>up) lo[i]=0; Dijkstra(1,n+1,dis); if(dis[n+1]<min)min=dis[n+1]; } cout<<min<<endl; return 0; } void Dijkstra(long s,long n,long *dist) { long vis[300]; long i,j,min,k; for(i=1;i<=n;i++) dist[i]=map[s][i]; for(i=1;i<=n;i++) vis[i]=1; vis[s]=0; for (j=1;j<n;j++){ min = 999999999; for (i=1;i<=n;i++) if (vis[i] && dist[i]>0 && dist[i]<min &&lo[i]) { min = dist[i]; k = i; } if (min == 999999999) break; vis[k] =0 ; for (i=1;i<=n;i++) if (vis[i] && map[k][i]!=MAX_INT &&lo[i] && (dist[k]+map[k][i]<dist[i] || dist[i] == 0)){ dist[i] = dist[k]+map[k][i]; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator