Pagini recente » Cod sursa (job #2415114) | Cod sursa (job #1954997) | Cod sursa (job #1090045) | Cod sursa (job #207915) | Cod sursa (job #1552864)
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
char buff[20];
int pos,sz,x,y,n,m;
struct Edge
{
int from,to,cost;
};
vector< pair<int,int> > G[250001];
struct comp
{
bool operator()(const pair<int,int>& a,const pair<int,int>& b)
{
return a.second > b.second;
}
};
priority_queue< pair<int,int>, vector< pair<int,int> >, comp> Q;
int nextInt()
{
int Ret = 0;
if (buff[pos] == ' ') ++pos;
while (buff[pos] >= '0' && buff[pos] <= '9' && pos < sz)
{
Ret = Ret * 10 + buff[pos] - '0';
pos++;
}
return Ret;
}
void read(Edge& e)
{
fgets(buff,20,stdin);
pos = 0; sz = strlen(buff);
e.from = nextInt(); e.to = nextInt(); e.cost = nextInt();
}
int dist[250001];
void Dijkstra()
{
memset(dist,0x3f3f3f3f,sizeof dist);
Q.push(make_pair(x,-1));
int u,d,nd;
while (!Q.empty())
{
u = Q.top().first;
d = Q.top().second;
Q.pop();
for (vector< pair<int,int> >::iterator it = G[u].begin(); it != G[u].end(); it++)
{
nd = max (d,it->second);
if (dist[it->first] > nd)
{
dist[it->first] = nd;
Q.push(make_pair(it->first,nd));
}
}
}
}
int main()
{
freopen("pscnv.in", "r", stdin);
freopen("pscnv.out", "w", stdout);
scanf("%d%d%d%d\n",&n,&m,&x,&y);
Edge e;
for (int i = 1; i <= m; i++)
{
read(e);
G[e.from].push_back(make_pair(e.to,e.cost));
}
Dijkstra();
printf("%d\n",dist[y]);
}