Cod sursa(job #1709848)

Utilizator UTCN_heapstrUTCN HeapStr UTCN_heapstr Data 28 mai 2016 14:10:14
Problema Politie Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.48 kb
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <set>

using namespace std;

typedef struct {
	int dst;
	int t, c;
} Edge;

struct Compfunc
{
	bool operator ()(const Edge &a, const Edge &b)
	{
		if (a.t == b.t) {
			return a.c > b.c;
		}
		
		return a.t > b.t;
	}
};

struct Comp2
{
	bool operator ()(const int &a, const int &b)
	{
		return a > b;
	}
};

int n, m, d, p, x, y, t, c;
bool viz[250001];
vector<Edge> neighb[250001];
Edge e;
set<int,Comp2> per;

void prim(int x) {
	priority_queue<Edge, vector<Edge>, Compfunc> pq;
	Edge e;

	viz[x] = true;
	for (int i = 0; i < neighb[x].size(); i++) {
		pq.push(neighb[x][i]);
	}

	while (!pq.empty()) {
		e = pq.top(); pq.pop();
		if (!viz[e.dst]) {
			viz[e.dst] = true;
			per.insert(e.c);
			for (int i = 0; i < neighb[e.dst].size(); i++) {
				pq.push(neighb[e.dst][i]);
			}
		}
	}
}

int main(){
	freopen("politie.in", "r", stdin);
	freopen("politie.out", "w", stdout);

	scanf("%d%d%d%d", &n, &m, &d, &p);

	for (int i = 0; i<m; i++) {
		scanf("%d%d%d%d", &x, &y, &t, &c);
		e.dst = y;
		e.t = t;
		e.c = c;
		
		neighb[x].push_back(e);
		e.dst = x;
		neighb[y].push_back(e);
	}

	prim(1);


	int i = 0;
	for (set<int>::iterator it = per.begin(); it != per.end() && i < p; i++, it++) {
		printf("%d\n", *it);
	}

	return 0;
}