Cod sursa(job #1387947)

Utilizator radudorosRadu Doros radudoros Data 14 martie 2015 21:42:08
Problema Sate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#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);
}