Cod sursa(job #2943831)

Utilizator IvanAndreiIvan Andrei IvanAndrei Data 21 noiembrie 2022 18:14:27
Problema Lazy Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#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;
}