Pagini recente » Cod sursa (job #2733377) | Cod sursa (job #2457571) | Cod sursa (job #1597932) | Cod sursa (job #3220240) | Cod sursa (job #2943831)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in ("lazy.in");
ofstream out ("lazy.out");
#define ll long long
struct str{
int x, y, ind;
ll c1, c2;
bool operator < (const str &aux) const
{
if (c1 != aux.c1)
{
return c1 < aux.c1;
}
return c2 < aux.c2;
}
};
const int max_size = 2e5 + 1;
int t[max_size];
vector <str> mc;
int rad (int x)
{
if (x == t[x])
{
return x;
}
return t[x] = rad(t[x]);
}
int main ()
{
int n, m;
in >> n >> m;
for (int i = 1; i <= n; i++)
{
t[i] = i;
}
for (int i = 1; i <= m; i++)
{
str aux;
in >> aux.x >> aux.y >> aux.c1 >> aux.c2;
aux.ind = i;
mc.push_back(aux);
}
sort(mc.begin(), mc.end());
for (int i = 0; i < m; i++)
{
if (rad(mc[i].x) != rad(mc[i].y))
{
t[rad(mc[i].y)] = rad(mc[i].x);
out << mc[i].ind << '\n';
}
}
in.close();
out.close();
return 0;
}