Cod sursa(job #542170)

Utilizator andrei.12Andrei Parvu andrei.12 Data 25 februarie 2011 21:27:25
Problema Lazy Scor Ascuns
Compilator cpp Status done
Runda Marime 1.83 kb
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#define x first
#define y second

using namespace std;

const char iname[] = "lazy.in";
const char oname[] = "lazy.out";
const int maxn = 200005;
const long long inf = 100000000000000000LL;
struct muchie {
	int x, i;
	long long y, z;
	muchie(int _x,long long _y, long long _z, int _i): x(_x), i(_i), y(_y), z(_z){}
	bool operator<(muchie alfa) const {
		if (y != alfa.y)
			return y < alfa.y;
		return z > alfa.z;
	}
};

vector<muchie> E[maxn];
set<muchie> S;

int n, m, i, where[maxn], x, y, rez[maxn];
long long dis[maxn], profit[maxn], z, t;

int main() {
	freopen(lazy.in, "r", stdin);
	freopen(lazy.ouy, "w", stdout);
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; ++i)
		scanf("%d%d%lld%lld", &x, &y, &z, &t),
		E[x].push_back(muchie(y,z,t, i)),
		E[y].push_back(muchie(x,z,t, i));
	
	for (i = 1; i <= n; ++i)
		dis[i] = inf, profit[i] = -1, S.insert(muchie(i, dis[i], -1, 0));
	
	S.erase(muchie(1, dis[1], -1, 0));
	dis[1] = 0;
	profit[1] = 0;
	S.insert(muchie(1, dis[1], 0, 0));
	for (i = 1; i <= n; ++i) {
		if (i > 1)
			rez[++rez[0]] = (*S.begin()).i;
		x = (*S.begin()).x;
		//fprintf(stderr, "%d %lld %lld %d\n", x, dis[x], profit[x], where[x]); 
		S.erase(muchie(x, dis[x], profit[x], where[x]));
		dis[x] = -1;
		for (vector<muchie>::iterator it = E[x].begin(); it != E[x].end(); ++it)
			if (dis[it -> x] != -1 && muchie(it -> x, it -> y, it -> z, it -> i) < muchie(it -> x, dis[it -> x], profit[it -> x], where[it -> x]))
				S.erase(muchie(it -> x, dis[it -> x], profit[it -> x], where[it -> x])),
				dis[it -> x] = it -> y,
				profit[it -> x] = it -> z,
				where[it -> x] = it -> i,
				S.insert(muchie(it -> x, dis[it -> x], profit[it -> x], where[it -> x]));
	}

	sort(rez + 1, rez + rez[0] + 1);
	for (i = 1; i <= rez[0]; ++i)
		printf("%d\n", rez[i]);
}