Pagini recente » Cod sursa (job #787193) | Cod sursa (job #2320708) | Cod sursa (job #2773488) | Cod sursa (job #3122639) | Cod sursa (job #2313910)
#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;
}