Cod sursa(job #2660240)

Utilizator xCata02Catalin Brita xCata02 Data 18 octombrie 2020 16:34:18
Problema Lazy Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double 
#define endl "\n"
 
const int Nmax = 200001;
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;
	} else {
		tata[y] = x;
	}
	
	if(rang[x] == rang[y]) {
		rang[x]++;
	}
}

bool cmp(alabala a, alabala b) {
	if(a.c1 == b.c1) {
		return a.c2 > b.c2;
	}
	return a.c1 < b.c1;
}

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(), cmp);
		
	vector < int > sol;
	
	for(auto it : muchii) {
		int a = getDaddy(it.x);
		int b = getDaddy(it.y);
		
		if(a != b) {
			unire(a, b);
			sol.push_back(it.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();
	}
}