Pagini recente » Cod sursa (job #1090596) | Cod sursa (job #476639) | Cod sursa (job #1321166) | Cod sursa (job #533978) | Cod sursa (job #1552946)
#include <fstream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
int pos,sz,x,y,n,m;
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;
}
};
class InputReader
{
public:
InputReader() {}
InputReader(const char *file_name)
{
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(int &n)
{
while (buffer[cursor] < '0' || buffer[cursor] > '9')
advance();
n = 0;
while ('0' <= buffer[cursor] && buffer[cursor] <= '9')
{
n = n * 10 + buffer[cursor] - '0';
advance();
}
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance()
{
++cursor;
if (cursor == SIZE)
{
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
priority_queue< pair<int,int>, vector< pair<int,int> >, comp> Q;
int dist[250001];
void Dijkstra()
{
memset(dist,0x3f3f3f3f,sizeof dist);
Q.push(make_pair(x,-1));
int u,d,nd;
bool ok = 0;
while (!Q.empty())
{
u = Q.top().first;
d = Q.top().second;
Q.pop();
if (ok && u == y) return;
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));
}
}
ok = 1;
}
}
int main()
{
InputReader fin("pscnv.in");
ofstream fout("pscnv.out");
fin >> n >> m >> x >> y;
int a,b,c;
for (int i = 1; i <= m; i++)
{
fin >> a >> b >> c;
G[a].push_back(make_pair(b,c));
}
Dijkstra();
fout << dist[y];
}