Cod sursa(job #644018)

Utilizator d.andreiDiaconeasa Andrei d.andrei Data 5 decembrie 2011 03:17:13
Problema Lazy Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <algorithm>

using namespace std;

#define file_in "lazy.in"
#define file_out "lazy.out"


#define nmax 201001

int N,M,i;
int x[nmax];
int y[nmax];
int c[nmax];
int p[nmax];
int sol[nmax];
int nr=0;
int c1,c2,t1,t2;
int tata[nmax];
int ind[nmax];

int cmp(int a, int b) {
	
	return (((c[a]==c[b])&&(p[a]<p[b]))||(p[a]>p[b]));
}

int find(int x){
	
	if (x!=tata[x])
		tata[x]=find(tata[x]);
	return tata[x];
}

void unite(int i, int j) {
	
	tata[i]=j;
}

int main(){
	
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d %d", &N, &M);
	for (i=1;i<=M;++i){
		ind[i]=i;
		tata[i]=i;
		scanf("%d %d %d %d", &x[i], &y[i], &c[i], &p[i]);
	}
	
	sort(ind+1,ind+M+1,cmp);
	
	for (i=1;i<=M;++i){
		
		t1=find(x[ind[i]]);
		t2=find(y[ind[i]]);
		
		if (t1!=t2){
			unite(t1,t2);
			sol[++nr]=ind[i];
		}
	}
	
	for (i=1;i<N;++i)
		 printf("%d\n", sol[i]);
	
	return 0;
	
}