POJ Telephone Lines 二分+dijkstra
来源:互联网 发布:技术影响力 知乎 编辑:程序博客网 时间:2024/06/05 09:11
题目链接: 点我
题目大意: 可以将T条边的权值改为0,然后选一条从起点到终点最大权值边最小的路。
题目分析: 二分最大权值x,然后dijkstra,遇到小于等于x的路长度为0,大于x的长度为1,总长度不能超过T即可。
PS :本来写的深搜结果超时了。。。
Problem: 3662 User: ChenyangDuMemory: 516K Time: 110MSLanguage: C++ Result: Accepted#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<queue>using namespace std;const int maxn = 1000+5,INF = 10000000;int n,m,K,d[maxn];struct node{int v,d;};node Node(int v,int d){ node t; t.v = v; t.d = d; return t;}bool operator < (node a,node b){ return a.d>b.d;}struct edge{int t,l;};edge Edge(int t,int l){ edge r; r.t = t; r.l = l; return r;}vector <edge> G[maxn];bool bfs(int x){ for(int i=2;i<=n;i++)d[i] = INF; d[1] = 0; priority_queue <node> que; que.push(Node(1,0)); while(!que.empty()){ node t = que.top();que.pop(); if(t.v == n)return true; if(t.d > d[t.v])continue; for(int i=0;i<G[t.v].size();i++){ edge e = G[t.v][i]; int dd = e.l>x?1:0; if(d[e.t] > d[t.v] + dd){ d[e.t] = d[t.v] + dd; if(d[e.t] <= K)que.push(Node(e.t,d[e.t])); } } } return false;}int main(){ //freopen("in.txt","r",stdin); scanf("%d%d%d",&n,&m,&K); for(int a,b,l,i=0;i<m;i++){ scanf("%d%d%d",&a,&b,&l); G[a].push_back(Edge(b,l)); G[b].push_back(Edge(a,l)); } int l = -1,r = INF; while(l<r-1){ int mid = (r+l)>>1; if(bfs(mid))r = mid; else l = mid; } if(r == INF)cout<<"-1"; else cout<<r; return 0;}
阅读全文
0 0
- POJ Telephone Lines 二分+dijkstra
- POJ 3662 Telephone Lines (Dijkstra+二分)
- POJ 3662 Telephone Lines 二分答案+djk
- Poj 3662 Telephone Lines【二分+SPFA】
- POJ - 3662 Telephone Lines (二分 + 最短路)
- poj 3662 Telephone Linse 二分答案 +dijkstra
- POJ 3662 Telephone Lines
- POJ 3662: Telephone Lines
- POJ-3662-Telephone Lines
- POJ 3662 Telephone Lines
- POJ-3662Telephone Lines
- POJ 3662 Telephone Lines
- Telephone Lines POJ
- POJ--3662[Telephone Lines] 二分答案+缩点
- POJ 3662 Telephone Lines (SPFA、二分搜索)
- [POJ 3662] Telephone Lines (二分答案+SPFA)
- POJ 3662 Telephone Lines 电话线(二分答案+SPFA)
- Poj 3662 Telephone Lines(最短路+二分)
- JSON文件读取
- 列表与表格的使用(新手入门基础学习)
- EffectiveC++学习笔记-条款28|29
- 【Linux学习】Linux上vi(vim)编辑器使用教程
- android 手势控制
- POJ Telephone Lines 二分+dijkstra
- android 手势检测
- 天善智能网络爬虫学习~
- c++一些博客
- npm和yarn
- HBase(二)hbase shell常用语法
- 怪异盒模型和标准盒模型
- jdbc
- 面向对象编程之类的继承性