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 |
spfa,,,呵呵,,,刚学会的,,#include <iostream> using namespace std; #define oo 99999999 #define max(a,b) a>b?a:b #define N 110 bool vis[N]; int map[N][N]; int q[N]; int d[N]; int n; int spfa() { memset(vis,false,sizeof(vis)); int i; for(i=1;i<=n;i++) d[i]=oo; int tail=0,head=-1; vis[1]=true; q[tail]=1; d[1]=0; while(head!=tail) { int u=q[head=(head+1)%n]; vis[u]=false; int j; for(j=1;j<=n;j++) { if(d[j]>d[u]+map[u][j]) { d[j]=d[u]+map[u][j]; if(!vis[j]) { q[tail=(tail+1)%n]=j; vis[j]=true; } } } } int ans=INT_MIN; for(i=1;i<=n;i++) ans=max(ans,d[i]); return ans; } int main() { char s[20]; int i,j; while(scanf("%d",&n)!=-1) { for(i=2;i<=n;i++) { for(j=1;j<=i-1;j++) { scanf("%s",s); if(s[0]=='x') map[i][j]=map[j][i]=oo; else map[i][j]=map[j][i]=atoi(s); } } for(i=1;i<=n;i++) map[i][i]=0; printf("%d\n",spfa()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator