Pagini recente » Cod sursa (job #1535588) | Cod sursa (job #2687184) | Cod sursa (job #1695112) | Cod sursa (job #934261) | Cod sursa (job #543707)
Cod sursa(job #543707)
#include <algorithm>
using namespace std;
#define DIM 200005
struct muchie
{
int x,y,ind;
long long c1,c2;
};
long long cst_min,prf_max;
int t[DIM],r[DIM];
muchie v[DIM];
int N,M;
struct cmp
{
bool operator () (const muchie &a,const muchie &b) const
{
if (a.c1!=b.c1)
return a.c1<b.c1;
return a.c2>b.c2;
}
};
inline int find (int x)
{
if (x!=t[x])
t[x]=find (t[x]);
return t[x];
}
inline void unite (int x,int y)
{
if (r[x]<r[y])
t[x]=y;
else
t[y]=x;
if (r[x]==r[y])
++r[x];
}
void read ()
{
int i;
scanf ("%d%d",&N,&M);
for (i=1; i<=M; ++i)
{
v[i].ind=i;
scanf ("%d%d%lld%lld",&v[i].x,&v[i].y,&v[i].c1,&v[i].c2);
}
}
void solve ()
{
int i;
for (i=1; i<=N; ++i)
t[i]=i;
sort (v+1,v+M+1,cmp ());
for (i=1; i<=M; ++i)
if (find (v[i].x)!=find (v[i].y))
{
printf ("%d\n",v[i].ind);
cst_min+=v[i].c1;
prf_max+=v[i].c1*v[i].c2;
unite (find (v[i].x),find (v[i].y));
}
}
int main ()
{
freopen ("lazy.in","r",stdin);
freopen ("lazy.out","w",stdout);
read ();
solve ();
return 0;
}