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 ...
随机推荐
- Spring注解和标签的比较说明
待完善.... xml标签 注解 说明 xml的Spring约束头 @Configuration xml约束头表明这是用于spring的的配置文件 @Configuration注解表情这是用于Spri ...
- helm repository 相关
chart repo是一个可用来存储index.yaml与打包的chart文件的HTTP server.当要分享chart时,需要上传chart文件到chart仓库,任何一个能够提供yaml与tar文 ...
- Eclipse和Tomcat安装使用
Tomcat 1.下载地址:http://tomcat.apache.org/ 可以选择安装版或者压缩包版本 解压后: |-bin: 存放tomcat的命令. catalina.bat 命令: sta ...
- android webview 全屏100%显示图片
这里引用 第三方类库 implementation 'org.jsoup:jsoup:1.10.2' 定义工具类 HtmlUtils import org.jsoup.Jsoup; import or ...
- .net core + xunit 集成测试
xunit地址:https://github.com/xunit/xunit 一.利用请求来测试接口,主要是测试webapi控制器方法 ①添加xunit项目 ,然后引用我们的主项目,nuget: Mi ...
- python 字典转成对象
database = { "key1": { 'period':999, "data": { 'a':1, 'b':2, } }, "key2&quo ...
- 二分法构造AVL树
public class ConvertSortedArrayToBinarySearchTree { public static TreeNode sortedArrayToBST(int[] nu ...
- 原生Ajax的怎么用?
<script> function createXMLHttpRequest() { var xmlhttp; try { //先直接创建XMLHttpRequest xmlhttp = ...
- 解决:ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];
简记 使用SkyWalking用ES做存储,发现运行一段时间会提示ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index ...
- web项目文档总览
一个web项目的文档应该包含哪些部分 一.规范文档1.ui 设计规范2.js.css.html 编码规范3.后台程序编码规范4.文件层级及模块编码规范二.技术架构评审三.运行环境部署细则四.研发流程: ...