#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXSIZE = 100000;
struct Edge{
int b,c;
Edge(int b,int c):b(b),c(c){}
bool operator < (Edge const & edge) const {
return c>edge.c;
}
};
vector<Edge > road[MAXSIZE];
bool visit[MAXSIZE];
int dis[MAXSIZE];
int n,m;
priority_queue<Edge> pq;
int main(){
memset(dis, INF, sizeof(dis));
cin>>n>>m;
int a,b,c;
for (int i = 0; i < m; ++i) {
cin>>a>>b>>c;
a--,b--;
road[a].push_back(Edge(b,c));
road[b].push_back(Edge(a,c));
}
dis[0] = 0;
pq.push(Edge(0, 0));
while (!pq.empty()){
Edge edge = pq.top();
pq.pop();
int u = edge.b;
if (u == n-1)
break;
for (int i = 0; i < road[u].size(); ++i) {
int temp = road[u][i].b;
if (!visit[temp]&&dis[temp]>max(dis[u], road[u][i].c)){
dis[temp] = max(dis[u],road[u][i].c);
pq.push(Edge(temp, dis[temp]));
}
}
}
cout<<dis[n-1]<<endl;
}
CCF CSP 地铁修建
最新推荐文章于 2021-08-30 21:50:06 发布