Pagini recente » Cod sursa (job #1326564) | Statistici petrita ana maria (anny95) | Cod sursa (job #2149255) | Cod sursa (job #508869) | Cod sursa (job #1387947)
#include<fstream>
#include<vector>
#include<bitset>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
const int nmax = 30001;
vector<pair<int, int>>v[nmax];
bitset<nmax> viz;
int x, y;
int rez = -1;
void dfs(int s,int c)
{
viz[s] = 1;
if (s == y)
{
fout << abs(c);
}
for (auto it : v[s])
{
if (!viz[it.first])
{
if (s < it.first)
dfs(it.first, c + it.second);
else
dfs(it.first, c - it.second);
}
}
}
int main()
{
int n, m;
fin >> n >> m >> x >> y;
for (int i = 1; i <= m; i++)
{
int a, b, w;
fin >> a >> b>>w;
v[a].push_back(make_pair(b, w));
v[b].push_back(make_pair(a, w));
}
dfs(x,0);
}