Advertisement
Morass

Jarnik-Prim

Jan 16th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. //F means for!
  2. #define MX 128
  3. struct nd{
  4.     nd(int a,double w):t(a),w(w){};
  5.     int t;
  6.     double w;
  7.     bool operator<(const nd&r)const{return w>r.w;}
  8. };
  9. int cn[MX],N,m;
  10. double g[MX][MX];
  11. double spt(void){
  12.     double S(0);
  13.     memset(cn,0,sizeof(cn));
  14.     cn[0]=1;
  15.     priority_queue<nd> q;
  16.     for(int i(1);i<N;++i)
  17.         q.push(nd(i,g[0][i]));
  18.     while(!q.empty()){
  19.         S+=q.top().w;
  20.         int a(q.top().t);
  21.         cn[a]=1;
  22.         F(N)q.push(nd(i,g[a][i]));
  23.         while(!q.empty()&&cn[q.top().t])
  24.             q.pop();
  25.     }
  26.     return S;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement