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 |
这算是prime不?#include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define maxn 99999 int s[1005][1005],dis[1005],book[1005]; void init(int n){ int i,j; for(i=0;i<=n;i++){ for(j=0;j<=n;j++) s[i][j]=maxn; dis[i]=maxn,book[i]=0; } } int main(){ int n,m,i,j,k; while(cin>>n&&n){ cin>>m; init(n); while(m--){ int a,b,c; cin>>a>>b>>c; if(s[a][b]>c) s[a][b]=c,s[b][a]=c; } int maxx=maxn,t1=0,t2=0; book[1]=1; k=n; while(k--){ for(i=1;i<=n;i++){ if(book[i]){ for(j=2;j<=n;j++) { if(book[j]==0) { if(dis[j]>s[i][j]) dis[j]=s[i][j]; if(dis[j]<maxx) maxx=dis[j],t2=j; } } } } book[t2]=1; maxx=maxn; } k=0; for(i=2;i<=n;i++) k+=dis[i]; cout<<k<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator