Pagini recente » Cod sursa (job #694984) | Cod sursa (job #2685163) | Cod sursa (job #1290125) | Cod sursa (job #1167997) | Cod sursa (job #3272316)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
/***struct muchie
{
int x,y,cost;
bool operator< (muchie m) const
{
return x < m.x;
}
};*/
int n,m,s1,s2,dist[30002];
vector <pair<int,int>> liste[30002];
void Bfs()
{
int nod,cost;
queue <pair<int,int>> q;
for(auto e:liste[s1])
{
q.push({e.first,e.second});
dist[e.first]=e.second;
}
while(!q.empty())
{
nod=q.front().first;
cost=q.front().second;
q.pop();
for(auto e:liste[nod])
if(dist[e.first]==0)
if(e.first<nod)
{
dist[e.first]=cost-e.second;
q.push({e.first,dist[e.first]});
}
else
{
dist[e.first]=cost+e.second;
q.push({e.first,dist[e.first]});
}
}
}
int main()
{
int i,c,z,t;
fin>>n>>m>>s1>>s2;
for(i=1;i<=m;i++)
{
fin>>z>>t>>c;
liste[z].push_back({t,c});
liste[t].push_back({z,c});
}
//cout<<sizeof(b)/1024.0/10244;
Bfs();
fout<<dist[s2];
return 0;
}