Cod sursa(job #543902)

Utilizator GavrilaVladGavrila Vlad GavrilaVlad Data 28 februarie 2011 18:34:23
Problema Lazy Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <stdio.h>
#include <set>
#include <algorithm>

using namespace std;

#define maxn 200010
#define mod 100000000

int n, m, i, j, k, n1, n2, mc;
int t[maxn], a[maxn], b[maxn];
long long c1, c2, x1, x2, x3, x4, x5;
pair<pair<long long, long long>, int> v[maxn];

int tata(int nod)
{
    if(t[nod]==nod)
        return nod;

    int aux=tata(t[nod]);
    t[nod]=aux;
    return aux;
}

int main()
{
    freopen("lazy.in", "r", stdin);
    freopen("lazy.out", "w", stdout);
    scanf("%d%d", &n, &m);

    for(int i=1; i<=m; ++i)
    {
        k=0;
        scanf("%d%d%lld%lld", &a[i], &b[i], &c1, &c2);
        v[i]=make_pair(make_pair(c1, -c2), i);
    }

    sort(v+1, v+m+1);

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

    for(int i=1; i<=m; ++i)
    {
        n1=a[v[i].second];
        n2=b[v[i].second];
        mc=v[i].second;

        if(tata(n1)!=tata(n2))
        {
            printf("%d\n", mc);
            t[tata(n1)]=tata(n2);
        }
    }

    return 0;
}