Pagini recente » Cod sursa (job #1655096) | Cod sursa (job #1899999) | Cod sursa (job #710756) | Cod sursa (job #126701) | Cod sursa (job #998689)
Cod sursa(job #998689)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int NMAX = 250005, INF = 0x3f3f3f3f;
int N, M, Start, End, X, Y, C, Ans[NMAX];
vector<pair<int, int> > G[NMAX];
vector<int> List[1010];
int GetAns()
{
memset(Ans, INF, sizeof(Ans));
Ans[Start] = 0;
List[0].push_back(Start);
for(int i = 0; i <= 1000; ++ i)
for(int j = 0; j < List[i].size(); ++ j)
{
int Node = List[i][j];
if(Node == End) return i;
if(Ans[Node] != i) continue;
for(int k = 0; k < G[Node].size(); ++ k)
{
int NowCost = max(Ans[Node], G[Node][k].second);
if(NowCost >= Ans[ G[Node][k].first ]) continue;
Ans[ G[Node][k].first ] = NowCost;
List[NowCost].push_back( G[Node][k].first );
}
}
}
int main()
{
freopen("pscnv.in", "r", stdin);
freopen("pscnv.out", "w", stdout);
scanf("%i %i %i %i", &N, &M, &Start, &End);
for(int i = 1; i <= M; ++ i)
{
scanf("%i %i %i", &X, &Y, &C);
G[X].push_back(make_pair(Y, C));
G[Y].push_back(make_pair(X, C));
}
printf("%i\n", GetAns());
return 0;
}