Cod sursa(job #552440)

Utilizator IAmASuperCerealVictor Andrei IAmASuperCereal Data 12 martie 2011 12:55:53
Problema Sate Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<stdio.h>
#include<vector>
#define input "sate.in"
#define output "sate.out"
#define NMAX 30001

using namespace std;

bool been_there_done_that[NMAX];
int n,m,x,y;
vector<vector<pair<int, int> > >G;

void open()
{
	freopen(input,"r",stdin);
	freopen(output,"w",stdout);
}

void _where_the_magic_happens(int x, int d)
{
     if( x == y )
     {
         printf("%d\n",d);
         return;
     }
     
     for( int i=1;i<G[x].size();i++)
          if( !been_there_done_that[G[x][i].first] )
          {
              been_there_done_that[G[x][i].first]=true;
              _where_the_magic_happens( G[x][i].first,d+G[x][i].second);
          }
}


void read()
{
	int a,b,d;
	scanf("%d%d%d%d",&n,&m,&x,&y);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&a,&b,&d);
		G[a].push_back(make_pair(b,d));
		G[a].push_back(make_pair(a,-d));
	}
}

int main()
{
	open();
	read();
	_where_the_magic_happens(x,0);
	return 0;
}