Pagini recente » Monitorul de evaluare | Profil M@2Te4i | Rating Mirela (ciubotariu_mi) | Istoria paginii utilizator/lasa-ma | Cod sursa (job #1122738)
#include<cstdio>
#include<algorithm>
#define nmax 200005
using namespace std;
struct nod
{
int x;
int y;
int ind;
long long cost;
long long profit;
}v[nmax];
int n,i,j,k,tata[nmax],a,b,rez,m;
int cmp(const nod a,const nod b)
{
if (a.cost==b.cost)
return a.profit<b.profit;
return a.cost<b.cost;
}
int find(int x)
{
if (!tata[x]) return x;
return find(tata[x]);
}
int main()
{
freopen("lazy.in","r",stdin);
freopen("lazy.out","w",stdout);
scanf("%d %d",&n,&m);
for (i=1;i<=m;i++)
{
scanf("%d %d %lld %lld",&v[i].x,&v[i].y,&v[i].cost,&v[i].profit);
v[i].ind=i;
}
sort(v+1,v+n+1,cmp);
for (i=1;i<=m && rez<n-1;i++)
{
a=find(v[i].x);
b=find(v[i].y);
if (a!=b)
{
printf("%d ",v[i].ind);
rez++;
if (a>b)
tata[b]=a;else
tata[a]=b;
}
}
return 0;
}