题意:

  就是使不大于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. C. Permutation Cycle

    For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: Let g(i) be t ...

  2. Shell调试篇 转

    检查语法 -n选项只做语法检查,而不执行脚本. sh -n script_name.sh 启动调试 sh -x script_name.sh 进入调试模式后,Shell依次执行读入的语句,产生的输出中 ...

  3. 关于EL表达式中requestScope和param区别

    今天演示EL表达式的时候发现自己jsp的基础实在是薄弱,在这个很简单的问题上迷惑了很久. 首先在看遇到的问题: 在浏览器地址输入,表示传入一个参数test,值为123 http://localhost ...

  4. 20155222卢梓杰 实验九 Web安全基础

    实验九 Web安全基础 今天不多bb,打开webgoat就是干好吧 1.简单字符串sql注入 可以看到这个实验说明是 "下表允许用户查看其信用卡号码.尝试插入一个SQL字符串,以显示所有信用 ...

  5. VS编程,编辑WPF过程中,点击设计器中界面某一控件,在XAML中高亮突出显示相应的控件代码的设置方法。

    原文:VS编程,编辑WPF过程中,点击设计器中界面某一控件,在XAML中高亮突出显示相应的控件代码的设置方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net ...

  6. 汇编 fsub ,fmul,fdiv,fild,CVTTPS2PI 指令

    知识点:  浮点指令 fsub 一.浮点指令fsub 格式 fsub memvar // st0=st0-memvar 知识点:  浮点指令 fmul 一.浮点指令fmul 格式 fmul mem ...

  7. HTML基础之CSS

    CSS选择器 1.id选择器 2.class选择器 3.标签选择器 4.层级选择器(空格) 5.组合选择器(逗号) 6.属性选择器(中括号) <!DOCTYPE html> <htm ...

  8. python高并发和多线程的关系

    “高并发和多线程”总是被一起提起,给人感觉两者好像相等,实则 高并发 ≠ 多线程 多线程是完成任务的一种方法,高并发是系统运行的一种状态,通过多线程有助于系统承受高并发状态的实现.   高并发是一种系 ...

  9. Azure SQL Database Active Geo-Replication 简介

    对于数据库的维护来说,备份工作可谓是重中之重.MS Azure 当然也提供了很完善的数据库备份功能.但是在动手创建备份计划前请思考一下备份工作的真实目的.当然首先要保证数据的安全,一般来说定时创建数据 ...

  10. 用Beyond Compare比较文本时,忽略不重要文本的方法

    Beyond Compare是一款好用的文本比较工具,可以比较纯文本文件.源代码和HTML,Word文档.Adobe和pdf文件.在使用Beyond Compare比较文本文件时,有些不重要的文本差异 ...