Pagini recente » Istoria paginii runda/usu6 | Cod sursa (job #1844882) | Cod sursa (job #1362398) | Statistici Gabriel Gabriel (ogabiii) | Cod sursa (job #2585614)
//
// main.cpp
// sate
//
// Created by Eusebiu Rares on 19/03/2020.
// Copyright © 2020 Eusebiu Rares. All rights reserved.
//
#include <iostream>
#include "fstream"
#include "queue"
#include "vector"
#include "bitset"
std::fstream in ("sate.in", std::ios::in) ;
std::fstream out ("sate.out", std::ios::out) ;
const int MV = 35000 ;
std::vector<std::pair<int, int> > G[MV + 1] ;
int sol[MV + 1] ;
template <class T>
class Coada {
private :
T v[1000000] ;
int st, dr ;
public :
Coada() {
st = 1 ;
dr = 0 ;
}
void push(T val) {
v[++ dr] = val ;
}
T front() {
return v[st] ;
}
bool empty() {
return !(st <= dr) ;
}
void pop() {
st ++ ;
}
} ;
int main(int argc, const char * argv[]) {
int n, m, x, y ;
in >> n >> m >> x >> y ;
int a, b, d ;
for (int i = 1 ; i <= m ; ++ i) {
in >> a >> b >> d ;
G[a].push_back({b, d}) ;
G[b].push_back({a, -d}) ;
}
for (int i = 1 ; i <= n ; ++ i) {
sol[i] = MV + 1 ;
}
Coada<int> Q ;
Q.push(x) ;
sol[x] = 0 ;
while (!Q.empty()) {
int node = Q.front() ; Q.pop() ;
for (auto it : G[node]) {
if (sol[it.first] == MV + 1) {
sol[it.first] = sol[node] + it.second ;
Q.push(it.first) ;
if (it.first == y) {
out << sol[y] ;
return 0 ;
}
}
}
}
}