Pagini recente » Cod sursa (job #2498369) | Cod sursa (job #2707727) | Cod sursa (job #2302500) | Cod sursa (job #2146926) | Cod sursa (job #1816050)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("transport2.in");
ofstream fout("transport2.out");
struct cmp{
bool operator()(pair<int,int> a, pair<int,int> b){
return a.first < b.second;
}
};
int n, m, wmax[100100];
vector<pair<int, int>> G[100100];
priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> pq;
void dijkstra()
{
pq.push({10001, 1});
while(!pq.empty())
{
int w = pq.top().first;
int x = pq.top().second;
pq.pop();
for(int i=0; i<G[x].size(); ++i)
if(wmax[G[x][i].first] == 0)
{
wmax[G[x][i].first] = G[x][i].second;
pq.push({wmax[G[x][i].first], G[x][i]. first});
}
else if(wmax[G[x][i].first] < min(wmax[x], G[x][i].second))
{
wmax[G[x][i].first] = min(wmax[x], G[x][i].second);
pq.push({wmax[G[x][i].first], G[x][i]. first});
}
}
}
int main()
{
fin >> n >> m;
for(int i=0; i<m; ++i)
{
int x, y, w;
fin >> x >> y >> w;
G[x].push_back({y, w});
G[y].push_back({x, w});
}
dijkstra();
fout << wmax[n];
return 0;
}