Pagini recente » Monitorul de evaluare | Cod sursa (job #748090) | Cod sursa (job #346968) | Cod sursa (job #1105544) | Cod sursa (job #644018)
Cod sursa(job #644018)
#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;
}