Pagini recente » Cod sursa (job #1579101) | Cod sursa (job #1568213) | Cod sursa (job #2659165) | Cod sursa (job #2396505) | Cod sursa (job #1222881)
#include <fstream>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <utility>
#include <queue>
#include <bitset>
#define NMAX 250005
#define VALMAX 1005
using namespace std;
int n,s,t;
vector<pair<int,int> > graf[NMAX];
int dist[NMAX];
bitset<NMAX> viz;
queue<int> coada[VALMAX];
inline void dijkstra(){
for(int i=1;i<=n;i++)
dist[i]=VALMAX;
dist[s]=0;
coada[0].push(s);
int y;
vector<pair<int,int> >::iterator it;
bool stop=false;
for(int i=0;i<VALMAX;i++){
while(!coada[i].empty()){
y=coada[i].front();
coada[i].pop();
if(!viz[y]){
if(y==t){
stop=true;
break;
}
viz[y]=1;
for(it=graf[y].begin();it!=graf[y].end();it++)
if(max(dist[y],it->second)<dist[it->first]){
dist[it->first]=max(dist[y],it->second);
coada[dist[it->first]].push(it->first);
}
}
}
if(stop)
break;
}
}
ifstream cin("pscnv.in");
char sir[5000100];
int lung;
int poz;
inline void cit(){
cin.get(sir+1,5000100,'#');
lung=strlen(sir+1);
poz=1;
}
inline int extract(){
while(poz<=lung && !isdigit(sir[poz]))
poz++;
int nr=0;
while(poz<=lung && isdigit(sir[poz])){
nr*=10;
nr+=(sir[poz]-'0');
poz++;
}
return nr;
}
int main()
{
ios_base::sync_with_stdio(false);
ofstream cout("pscnv.out");
int m=0,a,b,c;
cin>>n>>m>>s>>t;
cit();
for(int i=1;i<=m;i++){
//cin>>a>>b>>c;
a=extract();
b=extract();
c=extract();
graf[a].push_back(make_pair(b,c));
}
dijkstra();
cout<<dist[t]<<'\n';
cin.close();
cout.close();
return 0;
}