Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("bac.txt");
- ofstream fout("k.out");
- const int inf=1<<20;
- int n,m,A[100][100],P[100];
- void citire()
- { int i,j,k,c;
- fin>>n>>m;
- for(i=1;i<n;i++)
- for(j=i+1;j<=n;j++)
- A[i][j]=A[j][i]=inf;
- for(int k=1;k<=m;k++)
- { fin>>i>>j>>c;
- A[i][j]=A[j][i]=c;
- }
- }
- int main()
- {
- int i,k,minn,x;
- int s=0;
- citire();
- for(i=2;i<=n;i++) P[i]=1;
- for(k=1;k<n;k++)
- {
- minn=inf;
- for(i=1;i<=n;i++)
- if(P[i] && A[P[i]][i]<minn)
- {
- minn=A[P[i]][i]; x=i;
- }
- s+=A[P[x]][x];
- for(i=1;i<=n;i++)
- if(P[i] && A[P[i]][i]>A[i][x])
- P[i]=x;
- P[x]=0;
- }
- cout<<s<<" ";
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement