Pagini recente » Cod sursa (job #2661570) | Cod sursa (job #1587435) | Cod sursa (job #383312) | Cod sursa (job #1066050) | Cod sursa (job #2123604)
#include <fstream>
#include <algorithm>
#include <set>
#define MAXN 250002
#define MAXM 500005
using namespace std;
ifstream fin("politie.in");
ofstream fout("politie.out");
struct str{
int x, y, tip, c;
bool operator < (const str& other) const {
if (tip == other.tip)
return c < other.c;
return tip < other.tip;
}
};
set <int> sol;
str muchie[MAXM];
int n, m, d, p, tata[MAXN];
inline void Read() {
fin >> n >> m >> d >> p;
for (int i = 1; i <= m; i++) {
fin >> muchie[i].x >> muchie[i].y >> muchie[i].tip >> muchie[i].c;
}
sort(muchie + 1, muchie + m + 1);
}
inline int father(int node) {
if (node != tata[node]) {
tata[node] = father(tata[node]);
}
return tata[node];
}
inline void APM() {
int v1, v2, contor = 0;
for (int i = 1; i <= n; i++)
tata[i] = i;
for (int i = 1; i <= m; i++) {
v1 = father(tata[muchie[i].x]);
v2 = father(tata[muchie[i].y]);
if (v1 != v2) {
tata[v1] = v2;
contor++;
sol.insert(muchie[i].c);
if (contor == n - 1) {
return;
}
}
}
}
bool descr(int A, int B) {
return A > B;
}
inline void Afisare() {
int contor = 0;
for (auto it = sol.rbegin(); it != sol.rend(); it++) {
fout << *it << "\n";
if (++contor == p)
return;
}
}
int main () {
Read();
APM();
Afisare();
fin.close(); fout.close(); return 0;
}