Pagini recente » Cod sursa (job #2767215) | Cod sursa (job #44941) | Cod sursa (job #629834) | Cod sursa (job #3288510) | Cod sursa (job #1943809)
#include <fstream>
#include <algorithm>
#include <string.h>
using namespace std;
ifstream f("lazy.in");
ofstream g("lazy.out");
int a,b,n,m,i,tata[200001],nr,xx,yy,s,viz[200001];
long long c1,c2;
struct du{
int x,y,poz;
long long cost1,cost2;}muchii[200001];
bool cmp(du u,du v)
{
if(u.cost1==v.cost1) return u.cost2>v.cost2;
return u.cost1<v.cost1;
}
int main()
{
f>>n>>m;
for(i=1;i<=m;i++){
f>>a>>b>>c1>>c2;
muchii[i].x=a;
muchii[i].y=b;
muchii[i].cost1=c1;
muchii[i].cost2=c2;
muchii[i].poz=i;
}
sort(muchii+1,muchii+m+1,cmp);
memset(tata,-1,sizeof(tata));
for(i=1;i<=m&&nr!=(n-1);i++){
xx=muchii[i].x;
yy=muchii[i].y;
while(tata[xx]>0)
xx=tata[xx];
while(tata[yy]>0)
yy=tata[yy];
if(xx!=yy){
viz[i]=1;
if(tata[xx]<tata[yy]){
tata[xx]+=tata[yy];
tata[yy]=xx;}
else{
tata[yy]+=tata[xx];
tata[xx]=yy;
}
nr++;
}
}
for(i=1;i<=m;i++)
if(viz[i]==1)
g<<muchii[i].poz<<'\n';
return 0;
}