SHARE
TWEET

hatzjohnule

a guest Sep 19th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. void suma(int v[101][101],int n,int x)
  7. {
  8.     int i,j,a[101]={},loc=x,km=0;
  9.     a[x]=1;
  10.     cout<<x<<" ";
  11.     for(j=1;j<=n;j++)
  12.      {
  13.          int mn=1000,k;
  14.          for(i=1;i<=n;i++)
  15.             if(a[i]==0)
  16.          {
  17.              if(v[x][i]<mn)
  18.              {
  19.                  mn=v[x][i];
  20.                  k=i;
  21.              }
  22.          }
  23.          cout<<k<<" ";
  24.          km+=v[x][k];
  25.          x=k;
  26.          a[x]=1;
  27.      }
  28.  
  29.     cout<<loc<<endl;
  30.     cout<<km+v[x][loc];
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36.     int n, v[101][101]={},i,j;
  37.     cin>>n;
  38.     for(i=1;i<=n;i++)
  39.         for(j=1;j<=n;j++)
  40.     {
  41.         cin>>v[i][j];
  42.         v[j][i]=v[i][j];
  43.     }
  44.  
  45.     suma(v,n,1);
  46.  
  47.     return 0;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top