Cod sursa(job #544543)

Utilizator andrei.dAndrei Diaconeasa andrei.d Data 1 martie 2011 19:39:44
Problema Lazy Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

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

#define nmax 201010

struct lazy{
	
	int x,y;
	long long c1,c2;
	int ind;
}
a[nmax];
int n,m,i;
int tata[nmax];
int ind[nmax];


int cmp(lazy a, lazy b){
	
	return ((a.c1<b.c1) || ((a.c1==b.c1) && (a.c2>b.c2)));
}

int father(int x){
	
	if (x!=tata[x])
		tata[x]=father(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){
		
		scanf("%d %d %lld %lld", &a[i].x, &a[i].y, &a[i].c1, &a[i].c2);
		
		a[i].ind=i;
		tata[i]=i;
	}
	
	sort(a+1,a+m+1,cmp);
	int viz[nmax];
	for (i=1;i<=m;++i){
		
		int t1=father(a[i].x);
		int t2=father(a[i].y);
		
		if (t1!=t2){
			
			unite(t1,t2);
			viz[a[i].ind]=1;
		}
		
	}
	
	for (i=1;i<=m;++i)
		 if (viz[i])
			 printf("%d\n", i);
	
	return 0;
	
}