Cod sursa(job #1671518)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 1 aprilie 2016 20:25:32
Problema Lazy Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <cstdio>
#include <algorithm>
#define MAXM 200000
#define MAXN 200000
struct mycreation{
    int x, y, p;
    long long a, b;
}v[MAXM];
int t[MAXN+1], ans[MAXN];
bool cmp(const mycreation a, const mycreation b){
    if(a.a!=b.a)return a.a<b.a;
    return a.b>b.b;
}
int find(int x){
    if(t[x]==x)return x;
    t[x]=find(t[x]);
    return t[x];
}
int main(){
    int n, m, i;
    FILE *fin, *fout;
    fin=fopen("lazy.in", "r");
    fout=fopen("lazy.out", "w");
    fscanf(fin, "%d%d", &n, &m);
    for(i=0; i<m; i++){
        fscanf(fin, "%d%d%lld%lld", &v[i].x, &v[i].y, &v[i].a, &v[i].b);
        v[i].p=i+1;
    }
    std::sort(v, v+m, cmp);
    for(i=1; i<=n; i++){
        t[i]=i;
    }
    for(i=0; i<m; i++){
        if(find(v[i].x)!=find(v[i].y)){
            ans[++ans[0]]=v[i].p;
            t[find(v[i].x)]=find(v[i].y);
        }
    }
    for(i=1; i<n; i++){
        fprintf(fout, "%d\n", ans[i]);
    }
    fclose(fin);
    fclose(fout);
    return 0;
}