题目链接:https://nanti.jisuanke.com/t/31001


解题心得:

#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int maxn = 1e6+;
const ll INF = 1e12; ll n, m, k, S, T; struct edge {
ll to, len; edge(ll to1, ll len1):
to(to1), len(len1){};
}; struct NODE {
ll len, pos, c; bool friend operator < (NODE a, NODE b) {
return a.len > b.len;
} NODE (ll len1, ll pos1, ll c1):
len(len1), pos(pos1), c(c1){};
}; vector <edge> ve[maxn]; ll dis[][maxn]; void add_edge(ll u, ll v, ll len) {
ve[u].push_back(edge(v, len));
} void init() {
for(int i=;i<;i++)
for(int j=;j<maxn;j++)
dis[i][j] = INF; scanf("%lld%lld%lld",&n,&m,&k);
for(int i=;i<=n;i++)
ve[i].clear();
S = , T = n;
for(int i=;i<m;i++) {
ll u, v, len;
scanf("%lld%lld%lld",&u, &v, &len);
add_edge(u, v, len);
}
} void dij() {
priority_queue <NODE> qu;
qu.push(NODE(, S, ));
dis[][S] = ;
while(!qu.empty()) {
NODE now = qu.top(); qu.pop();
ll u = now.pos;
for(int i=;i<ve[u].size();i++) {
ll v = ve[u][i].to;
ll len = ve[u][i].len;
ll c = now.c;
if(dis[c][v] > dis[c][u]+len) {
dis[c][v] = dis[c][u] + len;
qu.push(NODE(dis[c][v], v, c));
}
} ll c = now.c;
if(c < k) {
for (int i = ; i < ve[u].size(); i++) {
ll v = ve[u][i].to;
if(dis[c+][v] > dis[c][u]) {
dis[c+][v] = dis[c][u];
qu.push(NODE(dis[c][u], v, c+));
}
}
}
}
} void min_path() {
dij();
ll Min = INF;
for(int i=;i<=k;i++) {
Min = min(Min, dis[i][T]);
}
printf("%lld\n", Min);
} int main() {
int t;
scanf("%d",&t);
while(t--) {
init();
min_path();
}
}

2018南京网络赛L题:Magical Girl Haze(最短路分层图)的更多相关文章

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

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

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

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

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

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

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

  6. The writing on the wall 南京网络赛2018B题

    样例输入复制 2 3 3 0 3 3 1 2 2 样例输出复制 Case #1: 36 Case #2: 20 题目来源 ACM-ICPC 2018 南京赛区网络预赛 题意: 就是求图中去掉涂黑的方格 ...

  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. 设计模式:仲裁者(Mediator)模式

    设计模式:仲裁者(Mediator)模式 一.前言     Mediator模式又称为仲裁者模式或者中介者模式,所起的作用是仲裁和中介,帮助其它类之间进行交流.在仲裁者模式之中,我们要明确两个概念,那 ...

  2. February 10 2017 Week 6 Friday

    Example is always more efficacious than precept. 身教胜于言教. Always match your words with your actions. ...

  3. ERP系统架构

    分布式.服务化的ERP系统架构设计 ERP之痛 曾几何时,我混迹于电商.珠宝行业4年多,为这两个行业开发过两套大型业务系统(ERP).作为一个ERP系统,系统主要功能模块无非是订单管理.商品管理.生产 ...

  4. PHP------析构方法

    析 构 方 法 封装,有一个叫构造函数 和构造函数对应的还有一种方法叫做析构. class ren    //一个类 是 人类 { public $mingzi ://成员变量 punction__d ...

  5. .net打印

    <input type="button" onclick="javascript:printit()"></input>//打印整个ht ...

  6. springboot多数据源的配置与使用

    转自:https://www.jianshu.com/p/34730e595a8c 之前在介绍使用JdbcTemplate和Spring-data-jpa时,都使用了单数据源.在单数据源的情况下,Sp ...

  7. PAT——1005. 继续(3n+1)猜想 (25)

    卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证的时候, ...

  8. Node.js笔记07——不使用generator自定义一个项目,深入了解项目结构

    一.初始化项目 新建项目 git init manager 新建view文件夹,建几个静态文件夹 新建app.js 快速初始化项目依赖 npm init -y 安装express npm instal ...

  9. php导出word格式数据的代码(转)

    本节内容:一个php导出文档的类 例子:<?php /*** 生成word文档的类* by www.jbxue.com*/class word{     function start()    ...

  10. Reading Notes : 180212 冯诺依曼计算机

    读书<计算机组成原理>,百度百科 现在大部分接触过计算机的人,都会知道冯诺依曼计算机,但是这个概念是怎么来的呢?本节我们就通过聊一下计算机的存储程序控制,来认识”冯诺依曼”. 存储程序控制 ...