Pagini recente » Cod sursa (job #540396) | Cod sursa (job #345450) | Cod sursa (job #2366008) | Cod sursa (job #1688311) | Cod sursa (job #2785026)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
const int NMAX = 250000;
const int MMAX = 500000;
struct strada {
int p;
int c;
int x;
int y;
} edges[MMAX + 1];
int father[NMAX + 1];
int root( int x ) {
if ( father[x] == x )
return x;
return ( father[x] = root( father[x] ) );
}
vector <int> ans;
void unire( strada a ) {
int rootx = root( a.x );
int rooty = root( a.y );
if ( rootx != rooty ) {
ans.push_back( a.p );
father[rootx] = rooty;
}
}
bool cmp( strada a, strada b ) {
return ( a.c < b.c || ( a.c == b.c && a.p < b.p ) );
}
ifstream fin( "politie.in" );
ofstream fout( "politie.out" );
int main() {
int n, m, p, d, i;
fin >> n >> m >> d >> p;
for ( i = 1; i <= n; i ++ )
father[i] = i;
for ( i = 1; i <= m; i ++ ) {
int x, y, c, pericol;
fin >> x >> y >> c >> pericol;
edges[i] = { pericol, c, x, y };
}
sort( edges + 1, edges + m + 1, cmp );
for ( i = 1; i <= m; i ++ ) {
unire( edges[i] );
}
sort( ans.begin(), ans.end() );
fout << ans[ans.size() - 1] << '\n';
p --;
for ( i = ans.size() - 2; i >= 0; i -- ) {
///fout << ans[i] << ' ';
if ( p > 0 && ans[i] != ans[i + 1] ) {
fout << ans[i] << '\n';
p --;
}
}
return 0;
}