Pagini recente » Cod sursa (job #1209402) | Cod sursa (job #3158649) | Cod sursa (job #779347) | Cod sursa (job #729623) | Cod sursa (job #2118432)
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a[31000];
bool viz[31000];
int rez[31000];
queue <int> q;
void dfs(int x, int c)
{
rez[x] = c;
viz[x] = 1;
for (int 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");
int n, m, x, y;
cin >> n >> m >> x >> y;
for (int i = 0; i < m; i++)
{
int x, y, z;
cin >> x >> y >> z;
pair<int, int> 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];
}