HDU5137How Many Maos Does the Guanxi Worth(最短路)
来源:互联网 发布:js控制display显示 编辑:程序博客网 时间:2024/05/16 23:26
题意:从2~n-1这几个点中任意去掉一个点,使得从1到n的最短路径最大,如果任意去掉一个点1~n无通路输出Inf。
思路:枚举去掉2~n-1个点,依次用spfa算法求取最短路,去最大即可
#include<bits/stdc++.h>using namespace std;#define pii pair<int, int>const int maxn = 35;int n, m;struct Edge{ int to, w; Edge(){} Edge(int to, int w):to(to), w(w){}};vector<Edge> a[maxn];int dis[maxn], fib;bool vis[maxn];void dij(int s){ memset(dis, 63, sizeof(dis)); memset(vis, false, sizeof(vis)); dis[s] = 0; vis[fib] = true; priority_queue<pii, vector<pii>, greater<pii> > q; q.push(pii(dis[s], s)); while(!q.empty()) { pii now = q.top(); q.pop(); int u = now.second, v; if(vis[u]) continue; for(int i = 0; i < a[u].size(); i++) { v = a[u][i].to; if(dis[v] > dis[u] + a[u][i].w) { dis[v] = dis[u] + a[u][i].w; q.push(pii(dis[v], v)); } } }}int main(){ int u, v, w; while(scanf("%d%d", &n, &m) != EOF) { if(n == 0 && m == 0) break; for(int i = 1; i <= n; i++) a[i].clear(); for(int i = 1; i <= m; i++) { scanf("%d%d%d", &u, &v, &w); a[u].push_back(Edge(v, w)); a[v].push_back(Edge(u, w)); } int ans = 0; for(fib = 2; fib < n; fib++) { dij(1); ans = max(ans, dis[n]); } if(ans == 0x3f3f3f3f) puts("Inf"); else printf("%d\n", ans); } return 0;}
阅读全文
0 0
- HDU5137How Many Maos Does the Guanxi Worth(最短路)
- hdu5137How Many Maos Does the Guanxi Worth【最短路最大值】
- 枚举+dijkstra(最短路删点) hdu5137How Many Maos Does the Guanxi Worth
- hdu5137How Many Maos Does the Guanxi Worth
- hdoj5137How Many Maos Does the Guanxi Worth【最短路】
- 【最短路】HDU5137 How Many Maos Does the Guanxi Worth
- hdu 5137 How Many Maos Does the Guanxi Worth (最短路SPAF实现)
- How Many Maos Does the Guanxi Worth 5137 (最短路+删点+最大边)
- HDOJ 5137 How Many Maos Does the Guanxi Worth(最短路)
- 2014广州站 K - How Many Maos Does the Guanxi Worth(floyed最短路)
- HDU 5137 How Many Maos Does the Guanxi Worth(最短路--dijkstra)
- 杭电-5137How Many Maos Does the Guanxi Worth(删点枚举+最短路)
- HDU 5137 How Many Maos Does the Guanxi Worth (最短路)
- HDU 5137 How Many Maos Does the Guanxi Worth(最短路)
- hdu1537How Many Maos Does the Guanxi Worth【最短路&&最短路径最大化】~
- hdoj 5137 How Many Maos Does the Guanxi Worth【最短路】
- HDU 5137 How Many Maos Does the Guanxi Worth (14广州 Floyd 最短路)
- HDU 5137--How Many Maos Does the Guanxi Worth【枚举 && 最短路 && spfa】
- C中结构体边界对齐
- 面试经验
- 21. Merge Two Sorted Lists
- 给定一个整数N,那么N的阶乘N!末尾有多少个0
- 文章标题
- HDU5137How Many Maos Does the Guanxi Worth(最短路)
- jsp 自定义标签 错误 : Unable to compile class for JSP: ,apache cannot be resolved or is not a field
- UILabel 竖行显示
- Filebeat简介
- java简易电话薄
- UVALive 6860 Most Influential Pumpkin
- 数据结构(一)
- Codeforces 363D Renting Bikes【二分+贪心】
- Java核心之接口、继承与多态