Pagini recente » Cod sursa (job #3262609) | Cod sursa (job #1876496) | Cod sursa (job #640099) | Cod sursa (job #144304) | Cod sursa (job #2118409)
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a[31000];
bool viz[31000];
queue <int> q;
int main()
{
ifstream cin("sate.in");
ofstream cout("sate.out");
int n, m, x, y, sum = 0;
cin >> n >> m >> x >> y;
for (int i = 0; i < m; i++)
{
int x, y, z;
cin >> x >> y >> z;
pair<int, int> w;
w.first = x;
w.second = z;
a[y].push_back(w);
w.first = y;
a[x].push_back(w);
}
int w = min(x,y);
y = max(x, y);
x = w;
q.push(x);
while (!(q.empty()))
{
int c = q.front();
q.pop();
viz[c] = 1;
if (c == y)
{
cout << sum;
return 0;
}
for (int i = 0; i < a[c].size(); i++)
if (!viz[a[c][i].first])
{
q.push(a[c][i].first);
if (c < a[c][i].first)
sum += a[c][i].second;
else
sum -= a[c][i].second;
break;
}
}
}