Pagini recente » Cod sursa (job #1467324) | Cod sursa (job #3186182) | Cod sursa (job #1649391) | Cod sursa (job #2457850) | Cod sursa (job #541688)
Cod sursa(job #541688)
#include <algorithm>
#include <fstream>
#include <vector>
using namespace std;
#define id first
#define x second.first.first
#define y second.first.second
#define c1 second.second.first
#define c2 second.second.second
const char Input[] = "lazy.in";
const char Output[] = "lazy.out";
const int Dim = 200001;
int N, M;
int r[Dim], t[Dim];
vector < pair < int, pair < pair <int, int>, pair <long long int, long long int> > > > m;
struct cmp {
bool operator()( pair < int, pair < pair <int, int>, pair <long long int, int> > > a, pair < int, pair < pair <int, int>, pair <long long int, int> > > b ) {
return a.c1 < b.c1 || ( a.c1 == b.c1 && a.c1 * a.c2 < b.c1 * b.c2 );
}
};
int Find( int a ) {
if( a != t[a] )
t[a] = Find( t[a] );
return t[a];
}
void Unite( int a, int b ) {
if( r[a] < r[b] )
t[a] = b;
else
t[b] = a;
if( r[a] == r[b] )
++r[a];
}
int main() {
ifstream fin( Input );
ofstream fout( Output );
int i, a, b, c, d, t1, t2;
vector < pair < int, pair < pair <int, int>, pair <long long int, long long int> > > > :: iterator it;
fin >> N >> M;
for( i = 1; i <= M; ++i ) {
fin >> a >> b >> c >> d;
m.push_back( make_pair( i, make_pair( make_pair( a, b ), make_pair( c, d ) ) ) );
}
sort( m.begin(), m.end(), cmp() );
// for( it = m.begin(); it != m.end(); ++it )
// fout << it->id << "\n";
for( i = 1; i <= N; ++i )
t[i] = i;
for( it = m.begin(); it != m.end(); ++it ) {
t1 = Find( it->x );
t2 = Find( it->y );
if( t1 != t2 ) {
Unite( t1, t2 );
fout << it->id << "\n";
}
}
fin.close();
fout.close();
return 0;
}