Cod sursa(job #562557)

Utilizator katakunaCazacu Alexandru katakuna Data 23 martie 2011 13:05:46
Problema Lazy Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

#define Nmax 200010

struct muchie {
	int x, y, c1, c2;
} M[Nmax];

int n, m;
int T[Nmax], Poz[Nmax], Sol[Nmax];

bool cmp (int a, const int b) {
   if (M[a].c1 == M[b].c1) return M[a].c2 > M[b].c2;
   return M[a].c1 < M[b].c1;
}

int Tata (int nod) {
	
	while (T[nod] >= 0)
		nod = T[nod];
	return nod;
}

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

	int i, t1, t2, x, y;

	scanf ("%d %d", &n, &m);
	for (i = 1; i <= m; i++) {
		scanf ("%d %d %d %d", &M[i].x, &M[i].y, &M[i].c1, &M[i].c2);
		Poz[i] = i; 
	}

	sort (Poz + 1, Poz + m + 1, cmp);

	memset (T, -1, sizeof (T));
	for (i = 1; i <= m; i++) {
		x = M[Poz[i]].x; y = M[Poz[i]].y;
		t1 = Tata (x); t2 = Tata (y);
		
		if (t1 == t2) continue;
		
		if (-T[t1] >= -T[t2]) 
			T[t1]+= T[t2], T[t2] = t1;
		else 
			T[t2]+= T[t1], T[t1] = t2;

		Sol[++Sol[0]] = Poz[i];
	}

	for (i = 1; i < n; i++)
		printf ("%d\n", Sol[i]);

	return 0;
}