Pagini recente » Cod sursa (job #2402068) | Profil M@2Te4i | Cod sursa (job #1259825) | Cod sursa (job #2104629) | Cod sursa (job #575094)
Cod sursa(job #575094)
#include <cstdio>
#include <algorithm>
#include <vector>
#define maxn 200010
using namespace std;
int c1[maxn], c2[maxn], t[maxn], rg[maxn], x[maxn], y[maxn], ind[maxn];
int n, m;
vector <int> sol;
inline bool cmp (const int &a, const int &b)
{
if (c1[a] == c1[b])
return c2[a] > c2[b];
return c1[a] < c1[b];
}
int group (int x)
{
if (t[x] == x) return x;
t[x] = group (t[x]);
return t[x];
}
void unite (int x, int y)
{
if (rg[x] < rg[y])
t[group (x)] = group (y);
else
t[group (y)] = group (x);
if (rg[x] == rg[y]) ++rg[y];
}
int main ()
{
freopen ("lazy.in", "r", stdin);
freopen ("lazy.out", "w", stdout);
int i;
scanf ("%d %d\n", &n, &m);
for (i = 1; i <= m; i++) {
scanf ("%d %d %d %d\n", &x[i], &y[i], &c1[i], &c2[i]);
ind[i] = i;
}
sort (ind + 1, ind + m + 1, cmp);
for (i = 1; i <= n; i++) t[i] = i, rg[i] = 1;
for (i = 1; i <= m; i++)
if (group (x[ind[i]]) != group (y[ind[i]])) {
sol.push_back (ind[i]);
unite (x[ind[i]], y[ind[i]]);
}
for (i = 0; i < sol.size (); i++)
printf ("%d\n", sol[i]);
return 0;
}