地铁修建
来源:互联网 发布:王健林 知乎 编辑:程序博客网 时间:2024/04/25 03:17
用到了动态规划思想,spfa
#include<iostream>#include<algorithm>#include<vector>#include<queue>using namespace std;const int oo = 1e9;const int MAXN = 1e5+5;const int MAXM = 2*1e5 + 5;int N,M;bool inq[MAXN] = {0};int opt[MAXN];struct edge{ int from; int to; int weight; edge(int _from, int _to, int _weight) :from(_from), to(_to), weight(_weight) {}};vector<edge> ve;vector<int> v[MAXN];void bfs(int s){ queue<int> q; q.push(s); inq[s] = true; opt[s] = 0; for(;!q.empty();){ int t = q.front(); q.pop(); inq[t] = false; for(int i = 0; i < v[t].size();i++){ int e = v[t][i]; int next = ve[e].to; int m; if((m = max(opt[t],ve[e].weight))<opt[next]){ opt[next] = m; if(!inq[next]){ q.push(next); inq[next] = true; } } } }}int main(){ scanf("%d%d",&N,&M); fill(opt+1,opt+N+1,oo); int f,t,w; for(int i = 0; i < M; i++){ scanf("%d%d%d", &f, &t, &w); ve.push_back(edge(f,t,w)); ve.push_back(edge(t,f,w)); v[f].push_back(ve.size()-2); v[t].push_back(ve.size()-1); } bfs(1); cout << opt[N] << endl; return 0;}
阅读全文
0 0
- 地铁修建
- ccf地铁修建
- CCF CSP 地铁修建
- CCF 地铁修建
- 【CSP201703-4】地铁修建
- ccf 修建地铁
- ccf-地铁修建
- 地铁修建 CCF
- ccf-2017034地铁修建
- Java 地铁修建
- ccf csp 地铁修建
- 第十次ccf 地铁修建
- ccf 201703-4 地铁修建
- 201703-4 地铁修建 ccf
- Dijkstra算法之地铁修建
- 地铁修建。看如何规划
- CCF 201703-4 地铁修建
- CCF 地铁修建(Dijkstra 变式)
- fabric源码解析22——Orderer服务的初始化
- Java开发快递物流项目(2)
- Hbase入门
- Hive文件存储格式
- linux vim编辑器之常用指令
- 地铁修建
- Java中List判断为空的方法
- oracle表基本操作流程
- 希尔(shell)排序
- 第十三周 【项目1
- 给QT程序(即.exe)添加一个漂亮的图标
- LeetCode-122. Best Time to Buy and Sell Stock II
- 从零开始前端学习[56]:js下的函数
- 冒泡排序法