Pagini recente » Cod sursa (job #1469518) | Cod sursa (job #2102593) | Cod sursa (job #2282305) | Cod sursa (job #2273034) | Cod sursa (job #1106580)
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#define SIZE 250005
#define SIZE_list 1005
#define cost first
#define node2 second
using namespace std;
int n, m, source, sink, min_cost, dist[SIZE];
vector < pair < int, int > > adj[SIZE];
vector <int> lst[SIZE_list];
inline void read();
inline void solve();
inline void write();
int main()
{
read();
solve();
write();
return 0;
}
inline void read()
{
freopen("pscnv.in", "r", stdin);
scanf("%d%d%d%d", &n, &m, &source, &sink);
int x, y, cost;
while( m-- )
{
scanf("%d%d%d", &x, &y, &cost);
adj[x].push_back( make_pair( cost, y ) );
}
}
inline void solve()
{
memset( dist, 0x3f, sizeof(dist) );
lst[ 0 ].push_back( source );
dist[ source ] = 0;
for(int cst = 0; cst <= 1000; ++cst)
{
min_cost = cst;
// for(vector < int > :: iterator it_lst = lst[ cst ].begin(); it_lst != lst[ cst ].end(); ++it_lst)
for(unsigned i = 0; i < lst[cst].size(); ++i)
{
int node = lst[cst][i];
// int node = *it_lst;
// printf("%d %d %d\n", node, pos, lst[cst].size());
if( node == sink )
return ;
if( dist[node] != min_cost )
continue;
for(vector < pair < int, int > > :: iterator it = adj[ node ].begin(); it != adj[ node ].end(); ++it)
{
int cost_tmp = max( min_cost, (*it).cost );
// printf("%d ", cost_tmp);
if( dist[ (*it).node2 ] > cost_tmp )
{
dist[ (*it).node2 ] = cost_tmp;
lst[ cost_tmp ].push_back( (*it).node2 );
}
}
}
}
}
inline void write()
{
freopen("pscnv.out", "w", stdout);
printf("%d\n", min_cost);
}