Pagini recente » Cod sursa (job #394002) | Cod sursa (job #3289894) | Cod sursa (job #940122) | Cod sursa (job #2954372) | Cod sursa (job #2831083)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
ifstream fin("politie.in");
ofstream fout("politie.out");
int n, m, d, p, a, b, c, root[250005];
vector<pair<pair<int, int>, pair<int, int>>> edges;
priority_queue<int> pq;
int getRoot(int x)
{
if ( root[x] != x )
root[x] = getRoot(root[x]);
return root[x];
}
void link(int x, int y)
{
root[y] = x;
}
int main()
{
fin >> n >> m >> d >> p;
for ( int i = 1; i <= m; i++ )
{
fin >> a >> b >> c >> d;
edges.push_back({ {c,d}, {a, b} });
}
for ( int i = 1; i <= n; i++ )
root[i] = i;
sort(edges.begin(), edges.end());
for ( auto edge : edges )
{
int roota = getRoot(edge.second.first);
int rootb = getRoot(edge.second.second);
if ( roota != rootb )
{
link(roota, rootb);
pq.push(edge.first.second);
}
}
int last = -1;
for ( int i = 1; i <= p; i++ )
{
if ( pq.top() == last )
{
i--;
pq.pop();
continue;
}
last = pq.top();
fout << pq.top() << "\n", pq.pop();
}
}