Pagini recente » Cod sursa (job #2518972) | Cod sursa (job #2754411) | Cod sursa (job #577261) | Cod sursa (job #17706) | Cod sursa (job #552437)
Cod sursa(job #552437)
#include<stdio.h>
#include<vector>
#define input "sate.in"
#define output "sate.out"
#define NMAX 3001
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;
}