The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail
题目链接:https://nanti.jisuanke.com/t/41305
题目说的很明白。。。只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std; typedef long long LL;
#define inf 1e14
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define rep__(i, j, k) for (int i = (j); i < (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
#define per__(i, j, k) for (int i = (j); i > (k); i--) const int N = ;
int head[N];
int cnt;
bool vis[N];
LL dis[N];
queue<int > que;
int n,m; struct Edge{
int to;
LL w;
int next;
}e[]; void add(int u,int v,LL w){
e[cnt].to = v;
e[cnt].w = w;
e[cnt].next = head[u];
head[u] = cnt++;
} void spfa(int s){ while(!que.empty()) que.pop();
rep__(i,,n){
vis[i] = false;
dis[i] = inf;
} dis[s] = ;
que.push(s); int u,v;
LL w;
while(!que.empty()){
u = que.front();
// cout << "u " << u << endl;
que.pop();
vis[u] = false;
for(int o = head[u]; ~o; o = e[o].next){
v = e[o].to;
w = e[o].w;
if(dis[v] > dis[u] + w){
dis[v] = dis[u] + w;
if(!vis[v]){
vis[v] = true;
que.push(v);
}
}
}
}
} int main(){ int T;
scanf("%d",&T); int u,v;
LL w;
rep(o,,T){
scanf("%d%d",&n,&m); rep__(i,,n) head[i] = -;
cnt = ; rep(i,,m){
scanf("%d%d%lld",&u,&v,&w);
add(u,v,w);
} // rep__(i,o,n){
// cout << " u " << i << endl; // for(int o = head[i]; ~o; o = e[o].next){
// cout << e[o].to << " " << e[o].w << endl;
// }
// } rep(i,,){
scanf("%d%d",&u,&v);
spfa(v);
printf("%lld\n",-dis[u]);
add(u,v,-dis[u]);
}
} getchar();getchar();
return ;
}
The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail的更多相关文章
- The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解
(施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出 ...
- [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)
>传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...
- 计蒜客 The Preliminary Contest for ICPC Asia Nanjing 2019
F Greedy Sequence You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each ...
- The Preliminary Contest for ICPC Asia Nanjing 2019
传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 B. super_log (广义欧拉降幂)
In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For examp ...
- 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019
题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...
- B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)
同:https://www.cnblogs.com/--HPY-7m/p/11444923.html #define IOS ios_base::sync_with_stdio(0); cin.tie ...
- H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)
题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...
- F. Greedy Sequence(主席树区间k的后继)(The Preliminary Contest for ICPC Asia Nanjing 2019)
题意: 查找区间k的后继. 思路: 直接主席树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio&g ...
随机推荐
- solr配置同义词,停止词,和扩展词库(IK分词器为例)
定义 同义词:搜索结果里出现的同义词.如我们输入”还行”,得到的结果包括同义词”还可以”. 停止词:在搜索时不用出现在结果里的词.比如is .a .are .”的”,“得”,“我” 等,这些词会在句子 ...
- [转帖]智能合约和 DApp
智能合约和 DApp https://www.jianshu.com/p/5e7df3902957 2018.10.08 19:50:41字数 3,403阅读 9,819 2017年11月份和2018 ...
- FastReport 程序员手册
一.使用TfrxReport 组件工作1.加载并存储报表默认情况下,报表窗体同项目窗体构存储在同一个DFM文件中.多数情况下,无须再操作,因而你就不必采用特殊方法加载报表.如果你决定在文件中存储报表窗 ...
- golang---命令源码文件与命令行参数
命令源码文件是程序的运行入口,是每个可独立运行的程序必须拥有的. import "flag" flag包实现了命令行参数的解析.每个参数认为一条记录,根据实际进行定义,到一个se ...
- 一起来学习.net core程序使用中介者模式:MediatR插件
中介者模式是一种常见的设计模式,旨再降低程序的耦合性,因为传统的三层模式层层之间需要显示的调用,必须上层依赖下层,耦合性很高,为了解耦,将所有的指令单独放在一个位置处理,其他位置均通过这个位置来间接的 ...
- drools -规则语法
文章结构 1. 基础api 2. FACT对象 3. 规则 4. 函数 1. 基础api 在 Drools 当中,规则的编译与运行要通过Drools 提供的各种API 来实现,这些API 总体来讲可以 ...
- 在配置和销售凭证 GET_CONFIG_MODE 间通信时内部出错
“在配置和销售凭证 GET_CONFIG_MODE 间通信时内部出错” 订单打开出现这种错误提示,多半是配置对象号问题. SAP NOTE 2019-09-27 901893901893 - Repo ...
- 浅谈 G1 GC 日志格式
在 Java9 中,G1 GC 将成为默认的垃圾收集器,G1 垃圾收集器的关键特性之一是能够在不牺牲吞吐量的同时,限制 GC 暂停时间(即可以设置所需的最大停顿时间). 由于 G1 GC 正在逐渐成为 ...
- Vue自定义组件中Props中接收数组或对象
原文:https://www.jianshu.com/p/904551dc6c15 自定义弹框组件时,需要在弹框内展示商品list,所以需要组件中的对应字段接收一个Array数组,默认返回空数组[], ...
- 2019 边锋游戏java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.边锋游戏等公司offer,岗位是Java后端开发,因为发展原因最终选择去了边锋游戏,入职一年时间了,也成为了面 ...