Pagini recente » Cod sursa (job #714205) | Cod sursa (job #2730371) | Cod sursa (job #400433) | Cod sursa (job #2479502) | Cod sursa (job #2660235)
#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;
struct alabala {
int x;
int y;
ll c1;
ll c2;
int index;
};
int tata[Nmax];
int rang[Nmax];
vector < alabala > muchii;
int getDaddy(int x) {
while(tata[x] != x) {
x = tata[x];
}
return x;
}
void unire(int x, int y) {
if(rang[x] < rang[y]) {
tata[x] = y;
}
if(rang[x] > rang[y]) {
tata[y] = x;
}
if(rang[x] == rang[y]) {
tata[x] = y;
rang[y]++;
}
}
void solve() {
int n, m; cin >> n >> m;
for(int i = 1; i <= m; i++) {
int x, y, c1, c2; cin >> x >> y >> c1 >> c2;
muchii.push_back({x, y, c1, c2, i});
}
for(int i = 1; i <= n; i++) {
rang[i] = 1;
tata[i] = 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;
});
vector < int > sol;
for(int i = 0; i < m; i++) {
int x = getDaddy(muchii[i].x);
int y = getDaddy(muchii[i].y);
if(x != y) {
unire(x, y);
sol.push_back(muchii[i].index);
}
}
for(auto it : sol) {
cout << it << " ";
}
}
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();
}
}