Pagini recente » Cod sursa (job #1337571) | Cod sursa (job #45397) | Cod sursa (job #270375) | Cod sursa (job #873086) | Cod sursa (job #2651684)
#include <cstdio>
#include <algorithm>
using namespace std;
pair < pair <long long,long long> ,pair <int, pair <int,int> > > v[200001];
int arb[200001];
int t[200001];
int rad (int x){
while (t[x]>0)
x=t[x];
return x;
}
int main()
{
FILE *fin=fopen ("lazy.in","r");
FILE *fout=fopen ("lazy.out","w");
int n,m,i,mu,x,y,rx,ry;
fscanf (fin,"%d%d",&n,&m);
for (i=1;i<=n;i++)
t[i]=-1;
for (i=1;i<=m;i++){
fscanf (fin,"%d%d%lld%lld",&v[i].second.first,&v[i].second.second.first,&v[i].first.first,&v[i].first.second);
v[i].first.second=-v[i].first.second;
v[i].second.second.second=i;
}
sort (v+1,v+m+1);
mu=0;
for (i=1;i<=m;i++){
x=v[i].second.first;
y=v[i].second.second.first;
//printf ("%d %d\n",x,y);
rx=rad(x);
ry=rad(y);
if (rx!=ry){
// trb sa le unesc pe x si y
mu++;
arb[mu]=v[i].second.second.second;
if (t[rx]<t[ry]){
t[rx]+=t[ry];
t[ry]=rx;
}
else {
t[ry]+=t[rx];
t[rx]=ry;
}
}
}
//fprintf (fout,"%d\n",mu);
for (i=1;i<=mu;i++)
fprintf (fout,"%d\n",arb[i]);
return 0;
}