Pagini recente » Cod sursa (job #2551937) | Cod sursa (job #2946744) | Cod sursa (job #1571291) | Cod sursa (job #1175703) | Cod sursa (job #528517)
Cod sursa(job #528517)
//solutia cu dijkstra
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const char iname[] = "pscnv.in";
const char oname[] = "pscnv.out";
const int nmax = 100005;
const int infinite= 2188989;
vector<pair <int, int > > Gr[nmax];
int n, m, i, x, y, c, a1, a2;
int Cost[nmax];
bool viz[nmax];
int extracted;
struct cmp
{
bool operator()(const int &a, const int &b)const
{
return (Cost[a] > Cost[b]);
}
};
priority_queue<int, vector<int>, cmp> Q;
void dijkstra()
{
Q.push(1);
viz[a1] = 1;
Cost[a1] = 299999;
while(!Q.empty())
{
extracted = Q.top();
Q.pop();
viz[extracted] = 0;
for(vector<pair <int, int> >::iterator it = Gr[extracted].begin(); it != Gr[extracted].end(); ++it)
{
if(Cost[(*it).first] > max(Cost[extracted], (*it).second))
{
Cost[(*it).first] = max(Cost[(*it).first],min(Cost[extracted], (*it).second));
Q.push((*it).first);
}
}
}
}
int main()
{
freopen(iname, "r", stdin);
freopen(oname, "w", stdout);
scanf("%d %d %d %d", &n, &m, &a1, &a2);
for(i = 1; i <= m; i ++)
{
scanf("%d %d %d", &x, &y, &c);
Gr[x].push_back(make_pair(y, c));
Gr[y].push_back(make_pair(x, c));
}
dijkstra();
printf("%d\n", Cost[a2]);
return 0;
}