查看题目

  最小化第K大值。    

  让我怀疑人生的一题目,我有这么笨?

 #include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <functional>
using namespace std;
#define maxv 1010
#define maxl 1000000
struct edge
{
int to, cost;
edge(){}
edge(int to, int cost) : to(to), cost(cost){}
};
typedef pair<int, int> P;
vector<edge> G[maxv];
int d[maxv];
int V, E;
int dij(int s, int x) {
priority_queue<P, vector<P>, greater<P> > que;
memset(d, 0X3f, V*sizeof(int));
d[s] = ;
que.push(P(, s));
while (!que.empty()) {
P p = que.top(); que.pop();
int v = p.second;
if (d[v] < p.first) continue;
for (int i = ; i < G[v].size(); ++i)
{
edge e = G[v][i];
int new_d = d[v] + (e.cost >= x ? : );
if (d[e.to] > new_d)
{
d[e.to] = new_d;
que.push(P(d[e.to], e.to));
}
}
}
return d[V-];
}
int main(void) {
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int K;
scanf("%d%d%d", &V, &E, &K);
for (int i = ; i < E; ++i) {
int A, B, L;
scanf("%d%d%d", &A, &B, &L);
--A, --B;
G[A].push_back(edge(B,L));
G[B].push_back(edge(A,L));
}
int l = , u = maxl+;
for (;(u-l) > ;) {
int m = (u+l) >> ;
if (dij(, m) > K) {
l = m;
} else {
u = m;
}
}
printf("%d\n", (l>maxl ? - : l));
return ;
}

POJ 3662 Telephone Lines(二分+最短路)的更多相关文章

  1. poj 3662 Telephone Lines(最短路+二分)

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6973   Accepted: 2554 D ...

  2. POJ 3662 Telephone Lines (二分+Dijkstra: 最小化第k大的值)

    题意 Farmer John想从电话公司修一些电缆连接到他农场.已知N个电线杆编号为1,2,⋯N,其中1号已经连接电话公司,N号为农场,有P对电线杆可连接. 现给出P对电线杆距离Ai,Bi,Li表示A ...

  3. POJ 3662 Telephone Lines (二分+dijkstra)

    题意: 多年以后,笨笨长大了,成为了电话线布置师.由于地震使得某市的电话线全部损坏,笨笨是负责接到震中市的负责人. 该市周围分布着N(1<=N<=1000)根据1……n顺序编号的废弃的电话 ...

  4. (poj 3662) Telephone Lines 最短路+二分

    题目链接:http://poj.org/problem?id=3662 Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total ...

  5. POJ 3662 Telephone Lines【Dijkstra最短路+二分求解】

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7214   Accepted: 2638 D ...

  6. poj 3662 Telephone Lines spfa算法灵活运用

    意甲冠军: 到n节点无向图,它要求从一个线1至n路径.你可以让他们在k无条,的最大值.如今要求花费的最小值. 思路: 这道题能够首先想到二分枚举路径上的最大值,我认为用spfa更简洁一些.spfa的本 ...

  7. poj 3662 Telephone Lines

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7115   Accepted: 2603 D ...

  8. POJ 3662 Telephone Lines (分层图)

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6785   Accepted: 2498 D ...

  9. poj 3662 Telephone Lines dijkstra+二分搜索

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5696   Accepted: 2071 D ...

随机推荐

  1. 【转】CSS样式覆盖规则

    大家都知道CSS的全称叫做“层叠样式表”,但估计很多人都不知道“层叠”二字的含义.其实,“层叠”指的就是样式的覆盖,当一个元素被运用上多种样式,并且出现重名的样式属性时,浏览器必须从中选择一个属性值, ...

  2. 10分钟使用纯css实现完整的响应式导航菜单栏的效果

    在开发hexo主题pixel的时候没有选择bootstrap和jquery实现响应式菜单,而是 使用了纯css实现响应式菜单,这个想法来自于You-Dont-Need-Javascript, 这个项目 ...

  3. <实训|第十二天>用LVM对linux分区进行动态扩容

    [root@localhost~]#序言在linux中,我们安装软件的途径一般有那些,你们知道吗?在linux中,如果你的磁盘空间不够用了,你知道如何来扩展磁盘吗?动态扩容不仅在工作中还是在其他方面都 ...

  4. ionic —— 开发环境搭建并编译运行第一个APP

    其实类似的环境已经玩了很多次了,最开始玩还是微信刚刚出来,那会儿没有智能机.只好安装一个模拟器,却只是为了注册一个微信.想想也就是够了~ 前前后后折腾了很多次,可是每一次都给人不一样的感觉,也许是这个 ...

  5. [POJ2404]Jogging Trails(中国旅行商问题)(一般图的匹配——状压DP)

    题目:http://poj.org/problem?id=2404 题意:有个n(n<=15)的点和m条无向边,每条边都有自己的权值.现在你要从某个点出发,每条边可以经过多次但要保证每条边至少走 ...

  6. P和NP问题

    1. 通俗详细地讲解什么是P和NP问题 http://blog.sciencenet.cn/blog-327757-531546.html   NP----非定常多项式(英语:non-determin ...

  7. Shell命令_Cron使用

    chkconfig crond on d表示damon,后台进程 chkconfig --list | grep crond crontab [选项] 选项: -e: 编辑crontab定时任务 -l ...

  8. DIV+CSS系统学习:转载

    第一部分 HTML 第一章 职业规划和前景 职业方向规划定位: web前端开发工程师 web网站架构师 自己创业 转岗管理或其他 web前端开发的前景展望: 未来IT行业企业需求最多的人才 结合最新的 ...

  9. Activiti 学习笔记记录

    官方在线用户手册(英文版):http://activiti.org/userguide/index.html 中文用户手册:http://www.mossle.com/docs/activiti/in ...

  10. highstock-处理时间需要处理世界时间偏移量

    highstock的数据格式采用的是[[时间,数据],[时间,数据],[时间,数据],[时间,数据]],而时间采用的是13位的毫秒值,如[1133136000000,69.66],采用的时间格式为UT ...