Pagini recente » Istoria paginii utilizator/mateasamuel | Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1773844)
#include <bits/stdc++.h>
#define maxN 200002
#define ll long long
using namespace std;
int n, m, f[maxN], ans[maxN];
struct edge
{
int x, y, p;
ll c1, c2;
bool operator < (const edge & e) const
{
if (c1 == e.c1)
return c2 > e.c2;
return c1 < e.c1;
}
} v[maxN];
void Union(int x, int y)
{
f[x] = y;
}
int root(int x)
{
if (!f[x])
return x;
return f[x] = root(f[x]);
}
void read()
{
freopen("lazy.in", "r", stdin);
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; ++ i)
{
scanf("%d %d %lld %lld", &v[i].x, &v[i].y, &v[i].c1, &v[i].c2);
v[i].p = i;
}
}
void solve()
{
int i;
sort(v + 1, v + m + 1);
for (i = 1; i <= m; ++ i)
{
int rx = root(v[i].x),
ry = root(v[i].y);
if (rx != ry)
{
//ans += v[i].c1;
ans[++ ans[0]] = v[i].p;
Union(rx, ry);
}
}
sort(ans + 1, ans + ans[0] + 1);
}
void write()
{
freopen("lazy.out", "w", stdout);
for (int i = 1; i <= ans[0]; ++ i)
printf("%d\n", ans[i]);
}
int main()
{
read();
solve();
write();
return 0;
}