Pagini recente » Cod sursa (job #2163307) | Cod sursa (job #640679) | Cod sursa (job #109011) | Cod sursa (job #1100127) | Cod sursa (job #2524884)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
const int NMAX = 100005;
vector< pair< int, int > > G[NMAX];
queue< int > Q;
bitset<NMAX> visited;
int N, M, X, Y;
int x, y, c;
int D[NMAX];
void Citire()
{
}
void BFS()
{
}
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(NULL);
fin >> N >> M >> X >> Y;
for(int i = 0; i < M; i++) {
fin >> x >> y >> c;
G[x].push_back({y, c});
G[y].push_back({x, c});
}
D[X] = 0;
visited[X] = 1;
Q.push(X);
while(!Q.empty()) {
int currentNode = Q.front();
Q.pop();
for(auto it : G[currentNode]) {
if(!visited[it.first]) {
if(it.first > currentNode)
D[it.first] = D[currentNode] + it.second;
else
D[it.first] = D[currentNode] - it.second;
if(it.first == Y) {
fout << D[Y] << "\n";
return 0;
}
}
Q.push(it.first);
visited[it.first] = 1;
}
}
}