Pagini recente » Cod sursa (job #1653071) | Cod sursa (job #1617589) | Cod sursa (job #700090) | Cod sursa (job #1063721) | Cod sursa (job #1336145)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define nmax 30005
#define inf (1<<30)
#define weight first
#define id second
using namespace std;
bool seen[nmax];
int n, m, x, y, w, source, target, best[nmax];
vector <pair <int, int>> v[nmax];
void explore(int x, int soFar) {
seen[x] = true;
for(auto y:v[x]) {
if(best[y.id] == 0) best[y.id] = inf;
best[y.id] = min(best[y.id], soFar + y.weight);
if(!seen[y.id]) explore(y.id, best[y.id]);
}
}
int main() {
ifstream f("sate.in");
ofstream g("sate.out");
f>>n>>m>>source>>target;
for(int i=1; i<=m; i++) {
f>>x>>y>>w;
v[x].push_back(make_pair(w, y));
v[y].push_back(make_pair(-w, x));
}
explore(source, 0);
/*
for(int i=1; i<=n; i++)
cout<<best[i]<<" ";
cout<<"\n";
*/
g<<best[target]<<"\n";
return 0;
}