Mai intai trebuie sa te autentifici.
Cod sursa(job #2465675)
Utilizator | Data | 30 septembrie 2019 18:11:54 | |
---|---|---|---|
Problema | Sate | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.95 kb |
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<queue>
#include<vector>
#include <list>
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
vector <pair <int,int> >a[30001];
queue <int > c;
int distanta[100024],p,viz[100025],N,M,X,Y,D;
int i,j,k;
int parcurg(int i)
{
viz[i]=1;
int j,v,d;
c.push(i);
while(c.size())
{
p=c.front();c.pop();
for(j=0;j<a[p].size();j++)
{
v=a[p][j].first;
d=a[p][j].second;
if(viz[v]==0)
{
viz[v]=1;
c.push(v);
if(p>v)
distanta[v]=distanta[p]-d;
else
distanta[v]=distanta[p]+d;
if(v==Y)
break;
}
}
}
}
int main()
{
f>>N>>M>>X>>Y;
for(k=1;k<=M;k++)
{
f>>i>>j>>D;
a[i].push_back({j,D});
a[j].push_back({i,D});
}
parcurg(X);
cout<<distanta[Y];
return 0;
}