Cod sursa(job #296378)

Utilizator toni2007Pripoae Teodor Anton toni2007 Data 4 aprilie 2009 18:23:18
Problema Sate Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <cstdio>
#include <vector>

using namespace std;

#define pb 	push_back
#define maxN 	30010

int D[maxN], viz[maxN], N, M, X, Y;
vector <int> A[maxN], C[maxN];

void df (int x) {
	viz[x] = 1;
	for (int i = 0; i < (int) A[x].size(); ++ i)
		if (!viz[A[x][i]]) {
			D[A[x][i]] = D[x] + C[x][i];
			df (A[x][i]);
		}
}
int main () {
        int a, b, c;

	freopen("sate.in", "r", stdin);
	freopen("sate.out", "w", stdout);

	scanf("%d%d%d%d", &N, &M, &X, &Y);

	for ( ; M -- ; ) {
		scanf("%d%d%d", &a, &b, &c);
		A[a].pb(b);
		A[b].pb(a);
		C[a].pb(c);
		C[b].pb(-c);
	}

        df (X);
	printf("%d\n", D[Y]);
}