Cod sursa(job #2313910)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 7 ianuarie 2019 17:03:31
Problema Sate Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <bits/stdc++.h>
using namespace std;

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

const int DIM = 1e5 + 57;

struct Drum
{
	int x, y, d;
};

Drum v[DIM];

int pos[DIM];

int main()
{
	int n, m, x, y;
	in >> n >> m >> x >> y;
	
	for(int i = 1; i <= m; i++)
	{
		in >> v[i].x >> v[i].y >> v[i].d;
	}
	
	pos[x] = 1;
	
	while(pos[y] == 0)
	{
		for(int i = 1; i <= m; i++)
			if(pos[v[i].x] != 0)
				pos[v[i].y] = pos[v[i].x] + v[i].d;
			else
				if(pos[v[i].y] != 0)
					pos[v[i].x] = pos[v[i].y] - v[i].d;
	}
	
	out << pos[y] - 1;
	
}