Pagini recente » Cod sursa (job #1358701) | Cod sursa (job #2359670) | Cod sursa (job #549760) | Cod sursa (job #2042375) | Cod sursa (job #2323439)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("sate.in" );
ofstream out ("sate.out");
const int N = 30001;
vector < pair <int, int> > a[N];
int q[N];
int scor[N];
bool viz[N];
int main()
{
int n, m, x, y, cap = 0 , coada = -1;
in >> n >> m >> x >> y;
for ( int i = 0; i < m; i++ )
{
pair < int, int > x1, x2;
in >> x1.first >> x2.first >> x2.second;
x1.second = x2.second;
a[x1.first].push_back(x2);
a[x2.first].push_back(x1);
}
q[++coada] = x;
while ( cap <= coada )
{
int x = q[cap++];
viz[x] = true;
for ( auto p : a[x])
{
if ( !viz[p.first] )
{
q[++coada] = p.first;
if ( x < p.first )
{
scor[p.first] = scor[x] + p.second;
}
else
{
scor[p.first] = scor[x] - p.second;
}
}
}
}
out << scor[y];
return 0;
}