Pagini recente » Cod sursa (job #2449693) | Cod sursa (job #2712488) | Cod sursa (job #3221636) | Cod sursa (job #1137261) | Cod sursa (job #1106588)
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <cctype>
#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;
char s[256];
while( m-- )
{
gets( s );
int len = strlen( s ) - 1, pos = 0;
x = y = cost = 0;
while( pos <= len )
{
if( isdigit(s[ pos ]))
{
int nr_tmp = 0;
while( isdigit( s[pos] ) )
{
nr_tmp = nr_tmp * 10 + s[ pos ] - 48;
++pos;
}
--pos;
if( !x )
x= nr_tmp;
else if( !y )
y= nr_tmp;
else
cost = nr_tmp;
}
++pos;
}
printf("%d %d %d\n", 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(unsigned it = 0; it < lst[cst].size(); ++it)
{
int node = lst[cst][it];
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);
}