Pagini recente » Cod sursa (job #2846300) | Cod sursa (job #2128616) | Cod sursa (job #1201104) | Cod sursa (job #649901) | Cod sursa (job #2118434)
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > a[31000];
bool viz[31000];
long long rez[31000];
queue <long long> q;
void dfs(long long x, long long c)
{
rez[x] = c;
viz[x] = 1;
for (long long i = 0; i < a[x].size(); i++)
if (!viz[a[x][i].first])
dfs(a[x][i].first, x < a[x][i].first ? c + a[x][i].second : c - a[x][i].second);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ifstream cin("sate.in");
ofstream cout("sate.out");
long long n, m, x, y;
cin >> n >> m >> x >> y;
for (long long i = 0; i < m; i++)
{
long long x, y, z;
cin >> x >> y >> z;
pair<long long, long long> w;
w.first = x;
w.second = z;
a[y].push_back(w);
w.first = y;
a[x].push_back(w);
}
dfs(x, 0);
cout << rez[y];
}