Cod sursa(job #2990838)

Utilizator AndreiCroitoruAndrei Croitoru AndreiCroitoru Data 8 martie 2023 17:10:35
Problema Sate Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#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];
}