Pagini recente » Cod sursa (job #2023402) | Cod sursa (job #1195763) | Cod sursa (job #2756070) | Cod sursa (job #1948024) | Cod sursa (job #2990838)
#include <bits/stdc++.h>
using namespace std;
const int N = 30001;
bool verif[N];
int dist[N];
vector <pair<int, int>> g[N];
//void bfs(int node)
//{
// queue <int> q;
// q.push(node);
// while(!q.empty())
// {
// for(auto next : g[node])
// {
// if(!verif[next.first])
// {
// q.push(next.first);
// dist[next.first] = dist[node] + next.second;
// }
// }
// q.pop();
// }
//}
void dfs(int node)
{
verif[node] = 1;
for(auto next : g[node])
{
if(!verif[next.first])
{
dist[next.first] = dist[node] + next.second;
dfs(next.first);
}
}
}
int main()
{
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 a, b, c;
cin >> a >> b >> c;
g[a].push_back({b, c});
g[b].push_back({a, -c});
}
dfs(x);
cout << dist[y];
}