Cod sursa(job #2652549)

Utilizator gheorghe_cristiGheorghe Florin Cristi gheorghe_cristi Data 25 septembrie 2020 09:05:31
Problema Lazy Scor 100
Compilator cpp-64 Status done
Runda apmtraining Marime 1.1 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("lazy.in");
ofstream fout("lazy.out");

struct Muchie {
    int a, b, poz;
    long long c1, c2;

    bool operator< (const Muchie &m) {
        if (c1 != m.c1)
            return c1 < m.c1;
        else
            return c2 > m.c2;
    }
};

Muchie aux;
vector<Muchie> muchii;
vector<int> sol;
int n, m, T[200005], p;

int rad(int x) {
    while (T[x] > 0)
        x = T[x];

    return x;
}

int main() {
    fin >> n >> m;

    for (int i=1;i<=n;++i)
        T[i] = -1;

    while (fin >> aux.a >> aux.b >> aux.c1 >> aux.c2) {
        p++;
        aux.poz = p;
        muchii.push_back(aux);
    }

    sort(muchii.begin(), muchii.end());

    for(auto muchie: muchii) {
        int ra = rad(muchie.a);
        int rb = rad(muchie.b);

        if (ra != rb) {
            sol.push_back(muchie.poz);

            if (T[ra] < T[rb]) {
                T[ra] += T[rb];
                T[rb] = ra;
            } else {
                T[rb] += T[ra];
                T[ra] = rb;
            }
        }
    }

    for (auto i: sol) {
        fout << i << "\n";
    }
}