There are N cities in the country, and M directional roads from u to v(1≤u,v≤n). Every road has a distance ci. Haze is a Magical Girl that lives in City 1, she can choose no more than K roads and make their distances become 0. Now she wants to go to City N, please help her calculate the minimum distance.

Input
The first line has one integer T(1≤T≤5), then following T cases.
For each test case, the first line has three integers N,M and K.
Then the following M lines each line has three integers, describe a road, Ui,Vi,Ci​. There might be multiple edges between u and v.
It is guaranteed that N≤100000,M≤200000,K≤10,0≤Ci≤1e9. There is at least one path between City 1 and City N.

Output
For each test case, print the minimum distance.

样例输入
1
5 6 1
1 2 2
1 3 4
2 4 3
3 4 1
3 5 6
4 5 2

样例输出
3

题意

给你一个图,问你从1到N最多让K条边为0的最短路

题解

d[i][j]代表到j点已经删去i条边的最小值

跑一遍dij

代码

 #include<bits/stdc++.h>
using namespace std; #define ll long long
const int maxn=1e5+,maxm=2e5+;
ll d[][maxn];
int n,m,k;
int head[maxn],cnt;
struct edge
{
int v,next;
ll w;
}edges[maxm];
struct node
{
ll w;
int v,k;
bool operator<(const node &D)const{
return w>D.w;
}
};
void dij()
{
memset(d,0x3f,sizeof d);
priority_queue<node>q;
q.push({,,});
d[][]=;
while(!q.empty())
{
auto u=q.top();q.pop();
if(u.v==n)return;
for(int i=head[u.v];i!=-;i=edges[i].next)
{
edge &v=edges[i];
if(u.k<k&&d[u.k+][v.v]>d[u.k][u.v])
q.push({d[u.k+][v.v]=d[u.k][u.v],v.v,u.k+});
if(d[u.k][v.v]>d[u.k][u.v]+v.w)
q.push({d[u.k][v.v]=d[u.k][u.v]+v.w,v.v,u.k});
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(head,-,sizeof head);
cnt=;
scanf("%d%d%d",&n,&m,&k);
for(int i=,u,v,w;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
edges[cnt].v=v;
edges[cnt].w=1LL*w;
edges[cnt].next=head[u];
head[u]=cnt++;
}
dij();
ll minn=0x3f3f3f3f3f3f3f3f;
for(int i=;i<=k;i++)
minn=min(minn,d[i][n]);
printf("%lld\n",minn);
}
return ;
}

ACM-ICPC 2018 南京赛区网络预赛 L.Magical Girl Haze(分层最短路)的更多相关文章

  1. ACM-ICPC 2018 南京赛区网络预赛 - L Magical Girl Haze (分层迪杰斯特拉)

    题意:N个点,M条带权有向边,求可以免费K条边权值的情况下,从点1到点N的最短路. 分析:K<=10,用dist[i][j]表示从源点出发到点i,免费j条边的最小花费.在迪杰斯特拉的dfs过程中 ...

  2. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

    262144K   There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v ...

  3. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze 最短路+分层图

    类似题解 There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v(1≤u, ...

  4. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze (分层dijkstra)

    There are NN cities in the country, and MMdirectional roads from uu to v(1\le u, v\le n)v(1≤u,v≤n). ...

  5. ACM-ICPC 2018 南京赛区网络预赛 L题(分层最短路)

    题目链接:https://nanti.jisuanke.com/t/31001 题目大意:给出一个含有n个点m条边的带权有向图,求1号顶点到n号顶点的最短路,可以使<=k条任意边的权值变为0. ...

  6. ACM-ICPC 2018 南京赛区网络预赛 L 【分层图最短路】

    <题目链接> 题目大意: 有N个城市,这些城市之间有M条有向边,每条边有权值,能够选择K条边 边权置为0,求1到N的最短距离. 解题分析: 分层图最短路模板题,将该图看成 K+1 层图,然 ...

  7. ACM-ICPC 2018 南京赛区网络预赛 L题(分层图,堆优化)

    题目链接: https://nanti.jisuanke.com/t/31001 超时代码: #include<bits/stdc++.h> using namespace std; # ...

  8. ACM-ICPC 2018 南京赛区网络预赛 L && BZOJ 2763 分层最短路

    https://nanti.jisuanke.com/t/31001 题意 可以把k条边的权值变为0,求s到t的最短路 解析  分层最短路  我们建立k+1层图 层与层之间边权为0,i 向 i+1层转 ...

  9. 【ACM-ICPC 2018 南京赛区网络预赛 L】Magical Girl Haze

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 定义dis[i][j]表示到达i这个点. 用掉了j次去除边的机会的最短路. dis[1][0]= 0; 在写松弛条件的时候. 如果用 ...

随机推荐

  1. tar 排除文件

    tar -cvf test.tgz test/ --exclude *.txt --exclude *.jpg

  2. 机器学习进阶-图像特征sift-SIFT特征点 1.cv2.xfeatures2d.SIFT_create(实例化sift) 2. sift.detect(找出关键点) 3.cv2.drawKeypoints(画出关键点) 4.sift.compute(根据关键点计算sift向量)

    1. sift = cv2.xfeatures2d.SIFT_create() 实例化 参数说明:sift为实例化的sift函数 2. kp = sift.detect(gray, None)  找出 ...

  3. air报错 Error: Error #3000: Illegal path name

    配置增加: <supportedProfiles>extendedDesktop desktop</supportedProfiles> fb: flash:

  4. Django--ORM(模型层)--多表(重重点)

    一.数据库表关系 单表 重复的字段太多,所以需要一对多,多对多来简化 多表 多对一 多对多 一对一 =============================================== 一对 ...

  5. JSP基本_EL式

    1.EL式下記二種類がある.① ${式} : JSPの出力(レンダリング)時に評価 (JSP2.0から)② #{式} : タグハンドラにより任意のタイミングで評価 (JSP2.1から) 2.オブジェク ...

  6. Delphi 字符串截取函数

    如果要使用LeftStr,RightStr,MidStr必需引用系统单元StrUtils; 声明变量Str:string; Str:=HelloWorld; 1,LeftStr(Str,2)=He;/ ...

  7. TypeScript语言学习笔记(1)

    基本类型 // 布尔型(Boolean) let isDone: boolean = false; // 数值型(Number) let decimal: number = 6; let hex: n ...

  8. Python在cmd上打印彩色文字

    在Windows上编写python程序时,有时候需要对输出的文字颜色进行设置,特别是日志显示,不同级别的日志设置不同的颜色进行展示可以直观查看.本文主要描述通过ctypes.windll.kernel ...

  9. 4.HTTP入门.md

    目录 什么是http协议 http协议:对浏览器客户端 和 服务器端 之间数据传输的格式规范 查看http协议的工具* 使用火狐的firebug插件(右键->firebug->网络) Ht ...

  10. 19.JDBC和数据库访问.md

    1.基本功能: Java通过JDBC完成: 2.基本类型,通常用最后一种 3.JDBC简介 Java连接SQL例子: 参考:http://blog.chinaunix.net/uid-20726500 ...