Pagini recente » Cod sursa (job #144772) | Cod sursa (job #1591345) | Cod sursa (job #1004433) | Cod sursa (job #1798769) | Cod sursa (job #379957)
Cod sursa(job #379957)
#include <fstream>
#include <vector>
#define MAXC 1010
#define MAXN 250010
using namespace std;
vector<int> L[MAXC];
vector<pair<int,int> > G[MAXN];
int N,M,X,Y;
int cost[MAXN];
inline int max(int x,int y){ return x>y?x:y; }
int main(){
ifstream fi("pscnv.in");
fi>>N>>M>>X>>Y;
for (int i=1;i<=M;++i){
int x,y,z;
fi>>x>>y>>z;
G[x].push_back(make_pair(y,z));
G[y].push_back(make_pair(x,z));
}
fi.close();
for (int i=1;i<=N;++i) cost[i]=MAXC;
cost[X]=0;
L[0].push_back(X);
for (int i=0;i<MAXC;++i)
for (unsigned int j=0;j<L[i].size();++j)
if (cost[L[i][j]]==i)
for (vector<pair<int,int> >::iterator it2=G[L[i][j]].begin();it2!=G[L[i][j]].end();++it2)
if (max(i,it2->second)<cost[it2->first]){
cost[it2->first]=max(it2->second,i);
L[max(it2->second,i)].push_back(it2->first);
}
ofstream fo("pscnv.out");
fo<<cost[Y]<<"\n";
fo.close();
return 0;
}