Pagini recente » Istoria paginii runda/test_9_10_13/clasament | Cod sursa (job #1886436) | Cod sursa (job #1051614) | Cod sursa (job #976947) | Cod sursa (job #2425383)
#include <fstream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
#define nmax 30100
int dr[nmax], st[nmax], cost[nmax];
int n, m, x, y;
void read_data() {
f >> n >> m >> x >> y;
for( int i = 1; i <= m; i++ ) {
int a , b, c;
f >> st[i] >> dr[i] >> cost[i];
}
}
int viz[nmax];
void solve() {
viz[x] = 1;
while( !viz[y] ) {
for( int i = 1; i <= m; i++ )
if( viz[ st[i] ] and !viz[dr[i]] ) viz[dr[i]] = viz[st[i]] + cost[i];
else if( !viz[st[i]] and viz[ dr[i] ] ) viz[st[i]] = viz[dr[i]] - cost[i] ;
}
g << viz[y] - 1;
}
int main() {
read_data();
solve();
return 0;
}