Pagini recente » Cod sursa (job #65182) | Cod sursa (job #2682510) | Cod sursa (job #1455418) | Cod sursa (job #668387) | Cod sursa (job #2660226)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
const int Nmax = 200000;
const int MODULO = 1e9 + 7;
int tata[Nmax], rg[Nmax];
struct alabala {
int x;
int y;
ll c1;
ll c2;
int indice;
};
vector < alabala > muchii;
int getDaddy(int nod) {
if(tata[nod] != nod) {
nod = tata[nod];
}
return nod;
}
void unire(int x, int y) {
if(rg[x] < rg[y]) {
tata[x] = y;
return;
}
if(rg[x] > rg[y]) {
tata[y] = x;
return;
}
if(rg[x] == rg[y]) {
tata[x] = y;
rg[y]++;
}
}
void solve() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int x, y;
ll c1, c2;
cin >> x >> y >> c1 >> c2;
muchii.push_back({x, y, c1, c2, i});
muchii.push_back({y, x, c1, c2, i});
}
sort(muchii.begin(), muchii.end(), [&](alabala a, alabala b) {
if(a.c1 == b.c1) {
return a.c2 > b.c2;
}
return a.c1 < b.c1;
});
for(int i = 1; i <= n; i++) {
rg[i] = 1;
tata[i] = i;
}
vector < int > ans;
for(alabala it : muchii) {
int x = getDaddy(it.x);
int y = getDaddy(it.y);
//cout << x << " " << y << endl;
if(x != y) {
unire(it.x, it.y);
ans.push_back(it.indice);
}
}
for(int i = 0; i <= n - 2; i++) {
cout << ans[i] << endl;
}
}
void fisier() {
freopen("lazy.in" , "r", stdin);
freopen("lazy.out", "w", stdout);
}
int main() {
ios_base::sync_with_stdio(0);
cin .tie(0);
cout.tie(0);
fisier();
int testCases = 1;
//cin >> testCases;
while(testCases--) {
solve();
}
}