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 |
不知道同样是两次dijstra 不知道为什么要转换矩阵 直接还起点和终点不好吗 竟然一直超时0.o#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define MAXX 10000000 using namespace std; int map[1001][1001]; int dis[1001],flag[1001],res[1001]; int m,n,p; void dijkstra(int x){ memset(flag,0,sizeof(flag)); for(int i=1;i<=m;i++) dis[i]=MAXX; dis[x]=0; for(int i=1;i<m;i++){ int minn=MAXX,s=-1; for(int j=1;j<=m;j++){ if(dis[j]<minn&&(!flag[j])){ minn=dis[j]; s=j; } } flag[s]=1; for(int j=1;j<=m;j++){ if(!flag[j]){ dis[j]=min(dis[j],map[s][j]+dis[s]); } } } } int main(){ scanf("%d%d%d",&m,&n,&p); for(int i=1;i<=m;i++){ res[i]=0; for(int j=1;j<=m;j++) map[i][j]=MAXX; } for(int i=0;i<n;i++){ int x,y,l; scanf("%d%d%d",&x,&y,&l); map[x][y]=min(map[x][y],l); } dijkstra(p); for(int i=1;i<=m;i++) dis[i]==MAXX ? res[i]=res[i]:res[i]=dis[i]; for(int i=1;i<=m;i++){ for(int j=1;j<i;j++){ int temp=map[i][j]; map[i][j]=map[j][i]; map[j][i]=temp; } } dijkstra(p); for(int i=1;i<=m;i++) dis[i]==MAXX ? res[i]=res[i]:res[i]+=dis[i]; int ans=0; for(int i=1;i<=m;i++){ ans=max(ans,res[i]); } printf("%d\n",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator