首页 技术 正文
技术 2022年11月19日
0 收藏 548 点赞 4,251 浏览 1251 个字

题意:

思路:

二分+Disjktra

二分一个值 如果某条边的边权比它小,则连上边权为0的边,否则连上边权为1的边

最后的d[n]就是最小要免费连接多少电话线。

//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 22222
int n,p,k,ans=-1,w[N],first[N],v[N],next[N],tot,d[N],vis[N];
void add(int x,int y,int z){w[tot]=z,v[tot]=y,next[tot]=first[x],first[x]=tot++;}
struct Node{int from,to,weight;}node[11111],jy;
bool operator<(Node a,Node b){return a.weight>b.weight;}
void Dijkstra(int x){
priority_queue<Node>pq;
memset(d,0x3f,sizeof(d));
memset(vis,0,sizeof(vis));
d[1]=0;jy.to=1,jy.weight=0;
pq.push(jy);
while(!pq.empty()){
Node t=pq.top();pq.pop();
if(!vis[t.to])vis[t.to]=1;
else continue;
for(int i=first[t.to];~i;i=next[i]){
if(!vis[v[i]]&&d[v[i]]>d[t.to]+w[i]){
d[v[i]]=d[t.to]+w[i];
jy.to=v[i],jy.weight=d[v[i]];
pq.push(jy);
}
}
}
}
bool check(int x){
memset(first,-1,sizeof(first)),tot=0;
for(int i=1;i<=p;i++)
{
if(node[i].weight<=x){
add(node[i].from,node[i].to,0);
add(node[i].to,node[i].from,0);
}
else
{
add(node[i].from,node[i].to,1);
add(node[i].to,node[i].from,1);
}
}
Dijkstra(x);
return d[n]<=k;
}
int main(){
scanf("%d%d%d",&n,&p,&k);
for(int i=1;i<=p;i++)
scanf("%d%d%d",&node[i].from,&node[i].to,&node[i].weight);
int l=0,r=0x3fffffff;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid))r=mid-1,ans=mid;
else l=mid+1;
}
printf("%d\n",ans);
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,117
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,589
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927