Cod sursa(job #2027161)

Utilizator robx12lnLinca Robert robx12ln Data 25 septembrie 2017 18:30:08
Problema Lazy Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include<fstream>
#include<algorithm>
#include<cstring>
using namespace std;
ifstream fin("lazy.in");
ofstream fout("lazy.out");
int t[200005], n, m, sol[200005], nr;
struct str{
    int a;
    int b;
    int ind;
    long long c;
    long long p;
} v[200005];
inline bool cmp( str A, str B ){
    if( A.c == B.c ){
        return A.p > B.p;
    }
    return A.c < B.c;
}
int rad( int x ){
    if( t[x] > 0 )
        return t[x];
    return x;
}
inline void apm(){
    memset( t, -1, sizeof(t) );
    sort( v + 1, v + m + 1, cmp );
    for( int i = 1; i <= m; i++ ){
        int x = rad( v[i].a );
        int y = rad( v[i].b );
        if( x != y ){
            if( t[x] < t[y] ){
                t[x] += t[y];
                t[y] = x;
            }else{
                t[y] += t[x];
                t[x] = y;
            }
            sol[++nr] = v[i].ind;
        }
    }
    return;
}
int main(){
    fin >> n >> m;
    for( int i = 1; i <= m; i++ ){
        fin >> v[i].a >> v[i].b >> v[i].c >> v[i].p;
        v[i].ind = i;
    }
    apm();
    for( int i = 1; i <= nr; i++ ){
        fout << sol[i] << "\n";
    }
    return 0;
}