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 |
你的代码可以过的……MAXNUM就101太吝啬了点吧?换成大的,2147483647就好了In Reply To:这道题太郁闷了,用dijkstra应该可以过呀,重边也考虑过了,但是还是不停的wa,难道是有向图 Posted by:cpp051300448324 at 2005-04-20 12:57:26 > #include<iostream> > #include<fstream> > #include<iomanip> > #define MAXNUM 101 > using namespace std; > > unsigned int Edge[1001][1001]; > unsigned int dist[1001]; > bool s[1001]; > > void shortPath(int n,int v){ > int i,j,w; > for(i=1;i<=n;i++){ > dist[i]=Edge[i][v]; > s[i]=0; > } > s[v]=1;dist[v]=0; > for(i=0;i<n-1;i++){ > unsigned int min=MAXNUM; > int u=v; > for(j=1;j<=n;j++){ > if(!s[j]&&dist[j]<min){ > u=j; > min=dist[j]; > } > } > s[u]=1; > for(w=1;w<=n;w++){ > if( !s[w] && Edge[u][w]<MAXNUM && dist[w]>Edge[u][w]+dist[u]){ > dist[w]=Edge[u][w]+dist[u]; > } > } > } > } > > int main(){ > int T,N; > //ifstream cin("tmp.txt"); > cin>>T>>N; > int i,j; > for(i=1;i<=N;i++){ > for(j=1;j<=N;j++){ > Edge[i][j]=MAXNUM; > } > } > for(i=1;i<=N;i++){ > Edge[i][i]=0; > } > for(i=0;i<T;i++){ > int x,y,tmp; > scanf("%d %d %d",&x,&y,&tmp); > if(tmp<Edge[x][y]){ > Edge[x][y]=tmp; > Edge[y][x]=tmp; > } > } > shortPath(N,N); > /* for(i=1;i<=N;i++){ > for(j=1;j<=N;j++){ > cout<<setw(5)<<Edge[i][j]<<' '; > } > cout<<endl; > } */ > cout<<dist[1]<<endl; > system("pause"); > return 0; > } > > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator