Cod sursa(job #2673555)

Utilizator robert.barbu27robert barbu robert.barbu27 Data 17 noiembrie 2020 10:44:27
Problema Sate Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define nmax 1000000
#define MMAX 100000
#define inf 1e18
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
bool viz[30005];
int dist[30005];
vector<pair<int,int> > adj[30005];
int n,m,x,y;
void dfs(int node,int d)
{
    viz[node]=1;
    dist[node]=d;
    for(auto x:adj[node])
    {
        if(viz[x.first]==0)
        {
            if(node<x.first)
            {
                dfs(x.first,d+x.second);
            }
            else
            {
                dfs(x.first,d-x.second);
            }
        }
    }
}
int main()
{
f>>n>>m>>x>>y;
if(x>y) swap(x,y);
for(int i=1;i<=m;i++)
{
    int a,b,c;
    f>>a>>b>>c;
    adj[a].pb({b,c});
    adj[b].pb({a,c});
}
dfs(x,0);
g<<abs(dist[y]);






}