【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

定义dis[i][j]表示到达i这个点。
用掉了j次去除边的机会的最短路。
dis[1][0]= 0;
在写松弛条件的时候。
如果用了去除边的机会。
就把机会+1再更新最短路就好。
用spfa会超时。
写个dijkstra+优先队列优化就ok
在dis[n][0..k]中找最小值就好。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define ms(a,b) memset(a,b,sizeof a)
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
const LL mod=1000000007;
LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
LL gcd(LL a,LL b) { return b?gcd(b,a%b):a;}
// head
using namespace std; const int N = 1e5;
const int K = 10;
const int M = 2e5; struct abc
{
int en,w,nex;
}bian[M+10]; int n,m,k,fir[N+10],totm; LL dis[N+10][K+5]; multiset< pair<LL,pair<int,int> > > myset; multiset< pair<LL,pair<int,int> > >::iterator it; int main(){
while (n>0){
n/=2;
n++;
n--;
n/=2;
}
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
memset(fir,255,sizeof fir);
totm = 0;
cin >> n >> m >> k;
rep1(i,1,m){
int x,y,z;
cin >> x >> y >> z;
totm++;
bian[totm].nex = fir[x];
fir[x] = totm;
bian[totm].en = y;
bian[totm].w = z;
}
memset(dis,255,sizeof dis);
dis[1][0] = 0;
myset.insert(make_pair(0,make_pair(1,0)));
while (!myset.empty()){
pair<LL,pair<int,int> > temp = (*myset.begin());
myset.erase(myset.begin());
int x = temp.second.first,times = temp.second.second; for (int i = fir[x];i!=-1;i = bian[i].nex)
{
int y = bian[i].en;LL w = bian[i].w;
if (dis[y][times]==-1 || dis[y][times]>dis[x][times]+w){
if (dis[y][times]!=-1){
it = myset.find(make_pair(dis[y][times],make_pair(y,times)));
myset.erase(it);
}
dis[y][times] = dis[x][times]+w;
myset.insert(make_pair(dis[y][times],make_pair(y,times)));
}
if (times+1<=k && ( dis[y][times+1]==-1 || dis[y][times+1]>dis[x][times]))
{
if (dis[y][times+1]!=-1)
{
it = myset.find(make_pair(dis[y][times+1],make_pair(y,times+1)));
myset.erase(it);
}
dis[y][times+1] = dis[x][times];
myset.insert(make_pair(dis[y][times+1],make_pair(y,times+1)));
}
}
}
LL mi = dis[n][0];
for (int i = 1;i <= k;i++)
if (dis[n][i]!=-1){
mi = min(mi,dis[n][i]);
}
cout<<mi<<endl;
}
return 0;
}

【ACM-ICPC 2018 南京赛区网络预赛 L】Magical Girl Haze的更多相关文章

  1. 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 ...

  2. ACM-ICPC 2018 南京赛区网络预赛 L.Magical Girl Haze(分层最短路)

    There are N cities in the country, and M directional roads from u to v(1≤u,v≤n). Every road has a di ...

  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 (分层迪杰斯特拉)

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

  5. 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). ...

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

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

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

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

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

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

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

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

随机推荐

  1. [Javascript] Deep Search nested tag element in DOM tree

    // For example you want to search for nested ul and ol in a DOM tree branch // Give example <ol&g ...

  2. 【solr基础教程之中的一个】Solr相关知识点串讲

           Solr是Apache Lucene的一个子项目.Lucene为全文搜索功能提供了完备的API.但它仅仅作为一个API库存在.而不能直接用于搜索. 因此,Solr基于Lucene构建了一 ...

  3. 【剑指offer】无聊的1+2+...+n

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27964027 题目描写叙述: 求1+2+3+...+n,要求不能使用乘除法.for.whi ...

  4. 每天五个java相关面试题(8)--spring篇

    首先呢,假设有从事前端开发的大神或者准备从事前端开发的小伙伴无意看到我这篇博客看到这段文字欢迎加我的QQ:[ 845415745 ].即将走入社会的菜鸟大学生有关于前端开发的职业问题想请教或者一起探讨 ...

  5. bzoj4956: [Wf2017]Secret Chamber at Mount Rushmore

    F......loyd? 这范围也是..... 然而大了也不会.... #include<cstdio> #include<iostream> #include<cstr ...

  6. Keras简单使用

    Keras简单使用在keras中建立模型测试自己的图片一些有用的函数(持续更新) Keras简单使用 在keras中建立模型 相对于自己写机器学习相关的函数,keras更能快速搭建模型,流程如下: 通 ...

  7. C# net winform wpf 发送post数据和xml到网页

    由于项目需要发送数据到网页 这里用aspx做测试 采用post以及get发送数据,页面进行数据  首先这个东西很简单很简单,基本上学过的都会,但是原谅一直搞cs几乎不搞bs的猿类吧.三四年没接触bs. ...

  8. Unity3d 销毁

    using UnityEngine; using System.Collections; public class destroy : MonoBehaviour { void Start () { ...

  9. python课程设计笔记(二)破冰基本语法

    python两种编程方式:交互式与文件式 交互式:语法练习,输一条运行一条 文件式:通用,执行一组语句 注释 #单行注释  ...XXXXX...多行注释 逻辑 没有大括号,按缩进确定逻辑——缩进格数 ...

  10. 1350 Taxi Cab Scheme DAG最小路径覆盖

    对于什么是DAG最小路径覆盖以及解题方法在我的另外的博客已经有了.http://www.cnblogs.com/Potato-lover/p/3980470.html 此题的题意: 公交车(出租车)车 ...