Pagini recente » Cod sursa (job #1011976) | Cod sursa (job #250665) | Cod sursa (job #2970364) | Cod sursa (job #410572) | Cod sursa (job #3272293)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
vector<pair<int,int>>l[30005];
int n,m,x,y,xs,ys,c,sum,viz[30005],d[30005];
void bfs(int nod)
{
d[nod]=0;
queue<int>q;
q.push(nod);
viz[nod]=1;
while(!q.empty())
{
auto curr=q.front();
q.pop();
for(auto next:l[curr])
{
if(!viz[next.first])
{
viz[next.first]=1;
q.push(next.first);
if(next.first>curr)
d[next.first]=next.second+d[curr];
else
d[next.first]=d[curr]-next.second;
}
}
}
}
int main()
{
fin>>n>>m>>xs>>ys;
for(int i=1;i<=m;i++)
{
fin>>x>>y>>c;
l[x].push_back({y,c});
l[y].push_back({x,c});
}
bfs(xs);
fout<<d[ys];
}