Cod sursa(job #543927)

Utilizator savimSerban Andrei Stan savim Data 28 februarie 2011 19:27:00
Problema Lazy Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <stdio.h>
#include <algorithm>

using namespace std;

#define MAX_N 200010
#define MAX_M 200010

int n, m;
int father[MAX_N], ind[MAX_N];

struct edge {
	int x, y, ind;
	long long c, p;
} E[MAX_M];

inline int cmp(const edge &A, const edge &B) {
	if (A.c != B.c)
		return A.c < B.c;
	return A.p > B.p;
}

inline int get_father(int x) {
	if (x == father[x])
		return x;

	father[x] = get_father(father[x]);
	return father[x];
}

void solve() {
	for (int i = 1; i <= n; i++)
		father[i] = i;

	for (int i = 1; i <= m; i++) {
    	int t1 = get_father(E[i].x);
		int t2 = get_father(E[i].y);

		if (t1 != t2) {
        	printf("%d\n", E[i].ind);
			father[t1] = t2;
		}
	}
}

int main() {

	freopen("lazy.in", "r", stdin);
	freopen("lazy.out", "w", stdout);

	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
    	scanf("%d %d %lld %lld", &E[i].x, &E[i].y, &E[i].c, &E[i].p);
    	E[i].ind = i;
	}

	sort(E + 1, E + m + 1, cmp);
	solve();

	return 0;
}