Pagini recente » Cod sursa (job #427078) | Cod sursa (job #2854808) | Cod sursa (job #2144866) | Cod sursa (job #1118659) | Cod sursa (job #544543)
Cod sursa(job #544543)
#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;
}