Cod sursa(job #2652636)

Utilizator BogauuuBogdan Ivancu Bogauuu Data 25 septembrie 2020 13:09:57
Problema Lazy Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

struct muchie
{
    int x,y,c1,c2,inc;
};

muchie v[200005];
int t[200005];

bool cmp(muchie a, muchie b)
{
    if (a.c1<b.c1) return 1;
    else return 0;
}

int rad(int x)
{
    while(t[x]!=0) x=t[x];
    return x;
}

int n,m,i,x,y,rx,ry,nr,w[200005];

int main()
{
    fin >> n >> m;
    for (i=1;i<=m;i++)
    {
        fin >> v[i].x >> v[i].y >> v[i].c1 >> v[i].c2;
        v[i].inc=i;
        v[i].c2*=v[i].c1;
    }
    sort (v+1,v+m+1,cmp);
    for (i=1;i<=m;i++)
    {
        x=v[i].x;
        y=v[i].y;
        rx=rad(x);
        ry=rad(y);
        if (rx!=ry)
        {
            nr++;
            w[nr]=v[i].inc;
            t[x]=ry;
        }
        if (nr==n-1) break;
    }
    for (i=1;i<=nr;i++) fout << w[i] << "\n";

    return 0;
}