Pagini recente » Cod sursa (job #3179823) | Cod sursa (job #3210506) | Cod sursa (job #2472696) | Cod sursa (job #1810256) | Cod sursa (job #1795180)
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("politie.in", "r", stdin);
freopen("politie.out", "w", stdout);
ios::sync_with_stdio(false);
int N, M, D, P;
vector<tuple<int, int, int, int>> v;
vector<int> daddy;
cin >> N >> M >> D >> P;
for(int i = 1; i <= M; ++i) {
int a, b, c, d;
cin >> a >> b >> c >> d;
v.emplace_back(c, d, a, b);
}
sort(v.begin(), v.end());
daddy.resize(N + 1);
for(int i = 1; i <= N; ++i)
daddy[i] = i;
function<void(int, int)> couple = [&daddy](int a, int b)->void {
daddy[a] = b;
};
function<int(int)> whos_ur_daddy = [&daddy, &whos_ur_daddy](int k)->int {
if(daddy[k] != k)
daddy[k] = whos_ur_daddy(daddy[k]);
return daddy[k];
};
set<int> dangerSet;
for(auto it : v) {
int left = get<2>(it), right = get<3>(it), cost = get<0>(it), danger = get<1>(it);
if(whos_ur_daddy(left) != whos_ur_daddy(right)) {
couple(whos_ur_daddy(left), whos_ur_daddy(right));
dangerSet.insert(-danger);
}
}
while(!dangerSet.empty() && P) {
--P;
cout << -*dangerSet.begin() << "\n";
dangerSet.erase(dangerSet.begin());
}
return 0;
}