Cod sursa(job #1709457)

Utilizator UNIBUC_Echipa_LachetaBicsi Nitu Velea UNIBUC_Echipa_Lacheta Data 28 mai 2016 12:23:25
Problema Politie Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 2.08 kb
#include <cassert>
#include <fstream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <bitset>
#include <ctime>
#include <set>
#include <cmath>
#include <iomanip>
#include <map>
#include <stack>
#include <vector>
#include <bitset>

#include <fstream>

using namespace std;

#define FOR(i, a, n) for (int i = a; i <= n; ++i)
#define ROF(i, n, a) for (int i = n; i >= a; i--)
#define FIT(i, v) for (auto &i : v)
#define pb push_back
#define mp make_pair
#define mt make_touple
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 2000003;
ll powmod(ll a, ll b) {ll res=1; a %= mod; assert(b >= 0); for(; b; b >>= 1) {if (b & 1) res = res * a % mod; a = a * a % mod;} return res;}

const int N = 250100;

ifstream fin("politie.in");
ofstream fout("politie.out");

struct edge {
    int x, y, t, c;
    
    edge(int x, int y, int t, int c): x(x), y(y), t(t), c(c) {
        
    }
    bool operator < (edge other) const {
        if (t != other.t) {
            return t < other.t;
        }
        return c < other.c;
    }
};

int d[N], f[N];

int parent(int x) {
    if (f[x]) {
        return f[x] = parent(f[x]);
    }
    return x;
}

bool unite(int a, int b) {
    a = parent(a);
    b = parent(b);
    if (a == b) {
        return false;
    }
    
    if (d[a] < d[b]) {
        f[a] = b;
    } else {
        f[b] = a;
        if (d[a] == d[b]) {
            d[a]++;
        }
    }
    return true;
}
int main() {
    int n, m, d, p;
    fin >> n >> m >> d >> p;
    
    vector<edge> edges;
    for (int i = 1; i <= m; ++i) {
        int x, y, t, c;
        fin >> x >> y >> t >> c;
        edges.push_back(edge(x, y,t,c));
    }
    
    sort(edges.begin(), edges.end());
    
    set<int> sol;
    for (auto &el: edges) {
        if (unite(el.x, el.y)) {
            sol.insert(el.c);
        }
    }
    
    auto it = sol.end();
    --it;
    for (int i = 1; i <= p; ++i, --it) {
        fout << *it << "\n";
        if (it == sol.begin()) {
            break;
        }
    }
}