Pagini recente » Cod sursa (job #2290252) | Cod sursa (job #1374576) | Cod sursa (job #2553450) | Cod sursa (job #2279100) | Cod sursa (job #2027150)
#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 int cmp( const str &A, const 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 <= n; 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;
}
}
}
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;
}