Cod sursa(job #1053428)

Utilizator ELHoriaHoria Cretescu ELHoria Data 12 decembrie 2013 19:10:44
Problema Sate Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.8 kb
#include <fstream>
#include <queue>
#include <vector>
#define PII pair<int,int>
#define st first
#define nd second
#define MP make_pair

using namespace std;

vector< PII > G[30002];

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

int N, M, X, Y, D[30002];

int bfs()
{
	queue<int> Q;
	int nod;
	Q.push(X);
	while (!Q.empty())
	{
		nod = Q.front(), Q.pop();
		for (vector< PII >::const_iterator w = G[nod].begin(); w != G[nod].end(); ++w)
		if (D[w->st] == 0 && w->st != X)
			D[w->st] = D[nod] + w->nd, Q.push(w->st);
	}
	return D[Y];
}

void read_data()
{
	int a, b, c;
	fin >> N >> M >> X >> Y;
	for (; M; M--)
	{
		fin >> a >> b >> c;
		G[a].push_back(MP(b, c));
		G[b].push_back(MP(a, -c));
	}

}

int main()
{
	read_data();
	fout << bfs() << '\n';
	return 0;
}