Codeforces 1196F. K-th Path
发现到 $K$ 不大,考虑有什么和 $K$ 有关的结论
发现答案似乎只会经过前 $K$ 小的边,如果边权第 $K$ 小的边有多条那么可以任意取
证明挺显然的吧,首先如果走了边权排名大于 $K$ 的边那么总的排名也一定大于 $K$,并且如果经过第 $K$ 名的边那么我们就只要考虑只走这一条边的路径,不然总路径排名也一定大于 $K$
那么对于第 $K$ 名的边我们不用考虑它对图的贡献,任取即可
然后把有用的边和点拿出来离散化一下,那么总点数小于等于 $800$ ,直接 $floyd$ 然后对所有路径排序即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=,M=2e5+;
int n,m,K;
struct edge {
int u,v,w;
edge (int _u=,int _v=,int _w=) { u=_u,v=_v,w=_w; }
inline bool operator < (const edge &tmp) const {
return w<tmp.w;
}
}E[M];
int d[N];
ll dis[N][N],D[N];
int main()
{
n=read(),m=read(),K=read(); int a,b,c;
for(int i=;i<=m;i++)
{
a=read(),b=read(),c=read();
E[i]=edge(a,b,c);
}
sort(E+,E+m+); int tot=;
for(int i=;i<=min(m,K);i++)
d[++tot]=E[i].u,d[++tot]=E[i].v;
sort(d+,d+tot+); tot=unique(d+,d+tot+)-d-;
memset(dis,0x3f,sizeof(dis));
for(int i=;i<=tot;i++) dis[i][i]=;
for(int i=;i<=min(m,K);i++)
{
int x=lower_bound(d+,d+tot+,E[i].u)-d;
int y=lower_bound(d+,d+tot+,E[i].v)-d;
dis[x][y]=dis[y][x]=E[i].w;
}
for(int k=;k<=tot;k++)
for(int i=;i<=tot;i++)
for(int j=;j<=tot;j++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
int cnt=;
for(int i=;i<=tot;i++)
for(int j=i+;j<=tot;j++) D[++cnt]=dis[i][j];
sort(D+,D+cnt+);
printf("%lld\n",D[K]);
return ;
}
Codeforces 1196F. K-th Path的更多相关文章
- codeforces#1196F. K-th Path(最短路,思维题)
题目链接: https://codeforces.com/contest/1196/problem/F 题意: 在无向图的所有最短路点对中,求出第$k$大 数据范围: $ 1 \leq k \leq ...
- K-th Path CodeForces - 1196F
题目链接:https://vjudge.net/problem/CodeForces-1196F 题意:从图中找出第K短的最短路,最短路:从一个点到另一个的最短距离. 思路:题目说了,每两个点之间的边 ...
- Codeforces gym102152 K.Subarrays OR
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...
- codeforces 1133E K Balanced Teams
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...
- Codeforces 1133E - K Balanced Teams - [DP]
题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...
- codeforces 762 D. Maximum path(dp)
题目链接:http://codeforces.com/problemset/problem/762/D 题意:给出一个3*n的矩阵然后问从左上角到右下角最大权值是多少,而且每一个点可以走上下左右,但是 ...
- codeforces 1269E K Integers (二分+树状数组)
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...
- codeforces 1282B2. K for the Price of One (Hard Version) (dp)
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
- Codeforces 544E K Balanced Teams (DP)
题目: You are a coach at your local university. There are nn students under your supervision, the prog ...
随机推荐
- 10.矩形覆盖 Java
题目描述 我们可以用2**1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个21的小矩形无重叠地覆盖一个2n的大矩形,总共有多少种方法? 思路 其实,倒数第一列要么就是1个2**1的矩形竖着放,要么就 ...
- [GIT]提交后版本恢复
如果在回退以后又想再次回到之前的版本,可以用relog查看commit id,再使用reset设置. 1.执行 relog 后: 展示的最前面的部分就是commit id,后面会用来作为恢复的 ...
- Centos7 yum install chrome
一.配置 yun 源 vim /etc/yum.repos.d/google-chrome.repo [google-chrome] name=google-chrome baseurl=http:/ ...
- 百度地图java 判断当前位置是否在多边形区域内
package com.haiyisoft.cAssistant.adapter.hessian; import java.awt.geom.Point2D;import java.util.Arra ...
- jQuery获取元素值以及设置元素值总结
html(): 1:用户获取元素内的HTML内容,如果元素包含子标签,会以整体的形式返回 2:只获取第一个元素的内容 3:只获取普通元素的内容,表单元素内容无法获取 html(val): 1:用来设置 ...
- 发布机制-A/B 测试:百科
ylbtech-发布机制-A/B 测试:百科 AB测试是为Web或App界面或流程制作两个(A/B)或多个(A/B/n)版本,在同一时间维度,分别让组成成分相同(相似)的访客群组(目标人群)随机的访问 ...
- JMeter4.0分布式调度压测部署
我们在Loadrunner学过使用Load Generator做肉鸡, 通过Controller来进行脚本和权重的分配来进行分布式压测, Jmeter作为当今的网红性能测试工具,这个功能必须是少不了的 ...
- php怎样获取当前页面文件名
因开发需要,常需要获取当前php文件的文件名.php获取当前文件名方法很简单,程序代码如下: <?php function php_self(){ $php_self=substr($_SERV ...
- java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list
package DisplayAuthors; import java.sql.*; public class DisplayAuthors { private static final Str ...
- Access denied for user XX
解决方法:将pom.xml中的mysql-connector-java降低版本(直接去maven仓库复制:https://mvnrepository.com/),比如: <!-- https:/ ...