Pagini recente » Cod sursa (job #737734) | Cod sursa (job #2672635) | Cod sursa (job #1123211) | Cod sursa (job #3269827) | Cod sursa (job #2304086)
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100100],x,y,n,p,op,rx,ry,s,k;
pair<int, pair<int,int> > pereche[400010];
pair<int,int> sol[400100];
int rad(int xx){
while(t[xx]>0){
xx=t[xx];
}
return xx;
}
int main(){
fin>>n>>p;
for(int i=1;i<=n;i++){
t[i]=-1;
}
for(int i=1;i<=p;i++){
fin>>pereche[i].first>>pereche[i].second.first>>pereche[i].second.second;
fout<<pereche[i].first<<" "<<pereche[i].second.first<<" "<<pereche[i].second.second<<"\n";
}
sort(pereche+1,pereche+p+1);
for(int i=1;i<=p;i++){
rx=rad(pereche[i].second.first);
ry=rad(pereche[i].second.second);
/*if(rx!=ry){
s+=pereche[i].first;
k++;
sol[k].first=pereche[i].second.first;
sol[k].second=pereche[i].second.second;
if(t[rx]<t[ry]){
t[rx]+=t[ry];
t[ry]=rx;
}
else{
t[ry]+=t[rx];
t[rx]=ry;
}
}
*/
}
fout<<s;
}