Pagini recente » Cod sursa (job #96621) | Cod sursa (job #970891) | Cod sursa (job #152467) | Cod sursa (job #1523950) | Cod sursa (job #3272331)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
struct Trei
{
int x, y, cost;
};
struct Trey
{
/// nod cost nod din care vin
int first, second, third;
};
int n, m, X, Y;
vector<pair <int, int>> G[30002];
queue<int> q;
bool ajuns;
int d[30002];
bitset<30002> viz;
void BFS()
{
int nod, cost, vin, a, b;
q.push(X);
d[X] = 0;
while(!q.empty())
{
int t = q.front();
q.pop();
for(auto w : G[t])
if(!viz[w.first])
{
viz[w.first] = true;
if(w.first > t) d[w.first] = d[t] + w.second;
else d[w.first] = d[t] - w.second;
q.push(w.first);
}
}
}
int main()
{
int i, j, c;
fin >> n >> m >> X >> Y;
while(m--)
{
fin >> i >> j >> c;
G[i].push_back({j, c});
G[j].push_back({i, c});
}
BFS();
fout << d[Y];
return 0;
}