Pagini recente » Cod sursa (job #2372158) | Istoria paginii runda/training-1/clasament | Cod sursa (job #1696161) | Cod sursa (job #276827) | Cod sursa (job #2030461)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream in("lazy.in");
ofstream out("lazy.out");
int arbore[200005];
pair< pair<long long,long long> , pair<int, pair<int,int> > > muchii[200005];
int find_root( int nod ){
if( arbore[nod] < 0 ){
return nod;
}
else{
return find_root( arbore[nod] );
}
}
int n,m,a,b,root_one, root_two, knot_one, knot_two;
long long c1,c2;
int main(){
in >> n >> m;
for (int i = 1; i <= m; i ++){
in >> a >> b >> c1 >> c2;
muchii[i].first.first = c1;
muchii[i].first.second = c2*-1;
muchii[i].second.first = a;
muchii[i].second.second.first = b;
muchii[i].second.second.second = i;
}
sort (muchii+1, muchii+m+1);
for (int i = 1; i <= n; i ++){
arbore[i] = -1;
}
for (int i = 1; i <= m; i ++){
knot_one = muchii[i].second.first;
knot_two = muchii[i].second.second.first;
root_one = find_root( knot_one );
root_two = find_root( knot_two );
if( root_one == root_two ){
continue;
}
else{
if( arbore[root_one] <= arbore[root_two] ){
arbore[root_one] += arbore[root_two];
arbore[root_two] = root_one;
}
else{
arbore[root_two] += arbore[root_one];
arbore[root_one] = root_two;
}
out << muchii[i].second.second.second<<"\n";
}
}
return 0;
}