题意:

  就是使不大于k条路的权值变为零后求最短路

解析:

  d[i][j]表示使j条路变为权值后从起点到点i的最短路径

这题不能用spfa做  tle

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x3f3f3f3f;
int n, m, k;
int vis[maxn][];
int d[maxn][];
map<int, map<int, int> > t;
struct edge{
int u,v, d;
edge(int u,int v,int d)
{
this->u = u;
this->v = v;
this->d = d;
} };
vector<edge> Edge;
vector<int> G[maxn<<];
struct node{
int u, d, y;
node(int d,int u, int y)
{
this->d = d;
this->u = u;
this->y = y;
}
bool operator < (const node& a) const {
return d > a.d;
}
};
void add(int u,int v,int d)
{
Edge.push_back(edge(u,v,d));
G[u].push_back(Edge.size()-);
}
void dijkstra(int s)
{
priority_queue<node> Q;
mem(d, INF);
d[s][] = ;
mem(vis,);
Q.push(node(, s, ));
while(!Q.empty())
{
node x = Q.top();Q.pop();
int u = x.u;
int y = x.y;
if(vis[u][y]) continue;
vis[u][y] = ;
for(int i=;i<G[u].size();i++)
{
edge e = Edge[G[u][i]];
if(d[e.v][y] > d[u][y] + e.d)
{
d[e.v][y] = d[u][y] + e.d;
Q.push(node(d[e.v][y],e.v, y));
}
if(y + <= k && d[e.v][y+] > d[u][y])
{
d[e.v][y+] = d[u][y];
Q.push(node(d[e.v][y+], e.v, y+));
}
}
}
} int main()
{
int T;
rd(T);
while(T--)
{
t.clear();
Edge.clear();
for(int i=; i<maxn; i++) G[i].clear();
rd(n), rd(m), rd(k);
int u, v, w;
for(int i=; i<m; i++)
{
rd(u), rd(v), rd(w);
if(!t[u][v] || t[u][v] > w)
t[u][v] = w;
}
for(int i=; i<=n; i++)
for(map<int, int>::iterator it = t[i].begin(); it!=t[i].end(); it++)
add(i, it->first, it->second);
dijkstra();
int mind = INF;
for(int i=; i<=k; i++)
mind = min(mind, d[n][i]);
cout<< mind <<endl;
} return ;
}

Magical Girl Haze 南京网络赛2018的更多相关文章

  1. 2018ICPC南京网络赛

    2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...

  2. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)

    Count The Pairs Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  4. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  5. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  6. 2019 南京网络赛A

    南京网络赛自闭现场 https://nanti.jisuanke.com/t/41298 二维偏序经典题型 二维前缀和!!! #include<bits/stdc++.h> using n ...

  7. ACM-ICPC 2018 南京网络赛

    题目顺序:A C E G I J L A. An Olympian Math Problem 打表,找规律,发现答案为n-1 C. GDY 题意: m张卡片,标号1-13: n个玩家,标号1-n:每个 ...

  8. 计蒜客 2018南京网络赛 I Skr ( 回文树 )

    题目链接 题意 : 给出一个由数字组成的字符串.然后要你找出其所有本质不同的回文子串.然后将这些回文子串转化为整数后相加.问你最后的结果是多少.答案模 1e9+7 分析 : 应该可以算是回文树挺裸的题 ...

  9. 2018 ICPC南京网络赛 L Magical Girl Haze 题解

    大致题意: 给定一个n个点m条边的图,在可以把路径上至多k条边的权值变为0的情况下,求S到T的最短路. 数据规模: N≤100000,M≤200000,K≤10 建一个立体的图,有k层,每一层是一份原 ...

随机推荐

  1. R语言入门 :基本数据结构

    1.向量 向量是R语言中最基本的数据类型,在R语言中没有单独的变量. (1)  创建向量 R语言中可以用 = 或者 <- 来赋值. 向量名 <- 向量 或  向量名 = 向量 向量的创建方 ...

  2. Octocat,看着喜欢就都下载下来了

    看见github的octocat很喜欢,就用c#写了个程序统统download了,附上一个比较高效的下载程序,以及文末的图片压缩包. 用到了Jumony解析网页. HttpClient client ...

  3. Luogu P1198 [JSOI2008]最大数

    我会用高级(???)的单调栈来打这道题吗? 线段树即可水过. 假设这个数列刚开始所有数都是0,然后我们每次只要进行一个点的修改和区间求和即可. 这不就是 线段树大法. 只要用一个len记录一下当前数列 ...

  4. Voronoi图与Delaunay三角剖分

    详情请见[ZJOI2018]保镖 题解随笔 - 99 文章 - 0 评论 - 112

  5. JavaScript快速入门-ECMAScript本地对象(Date)

    JavaScript中的Date 对象用于处理日期和时间. var myDate=new Date()  #Date 对象会自动把当前日期和时间保存为其初始值. 一.Date对象的方法 方法 示例 n ...

  6. onSaveInstanceState和onRestoreInstanceState触发的时机

    先看Application Fundamentals上的一段话: Android calls onSaveInstanceState() before the activity becomes vul ...

  7. node基础-文件系统-文件写操作

    文件操作频率最高的就是读跟写.nodejs的文件的读取API在<node基础-文件系统-读取文件>里已经简单介绍过,本文就简单介绍下nodejs的文件写API. nodejs的文件操作均提 ...

  8. 软件测试_测试工具_Loadrunner_IP欺骗

    一.设置IP欺骗的原因: 1.当某个IP的访问过于频繁或者访问量过大时,服务器会拒绝访问请求: 2.某些服务器配置了负载均衡,使用同一个IP不能测出系统的实际性能.Loadrunner中的IP欺骗通过 ...

  9. 高精度减法--C++

    高精度减法--C++ 仿照竖式减法,先对其,再对应位相减. 算法处理时,先比较大小,用大的减小的,对应位再比较大小,用于作为借位符. #include <iostream> #includ ...

  10. Unity XLua 官方教程学习

    一.Lua 文件加载 1. 执行字符串 using UnityEngine; using XLua; public class ByString : MonoBehaviour { LuaEnv lu ...