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 ...
随机推荐
- Javascript Asynchronous Investigation
介绍 同步任务:在主线程上排队执行的任务,只有前一个任务执行完毕,才能执行后一个任务: 异步任务:不进入主线程,而进入任务队列中的任务,只有任务队列通知主线程,某个异步任务可以执行了,这个任务才会进入 ...
- .NET Core 获取自定义配置文件信息
前言 .net core来势已不可阻挡.既然挡不了,那我们就顺应它.了解它并学习它.今天我们就来看看和之前.net版本的配置文件读取方式有何异同,这里不在赘述.NET Core 基础知识. ps:更新 ...
- 深度学习 NI-DL 框架
NI-DL 应用框架:图像分类,目标检测,分割提取. 底层:TensorFlow,Keras,Cuda,C/C++ 上层:C#.NET Winform [图像分类] 识别一张图片是否为某个类型的物体/ ...
- ssh服务器安装测试
ssh服务器搭建 作用:用于远程登录到服务器 (1)服务器端 安装ssh: $ sudo apt-get install openssh-server 查看ssh是否已经安装: $ sudo apti ...
- windows下的文件管理工具--total commander
https://www.ghisler.com/ http://www.guyiren.com/archives/1647
- [转帖]Linux firewalld 防火墙使用
Linux firewalld 防火墙使用 2018-06-19 19:26:08 蚩尤后裔 阅读数 2101 收藏 更多 分类专栏: Linux 版权声明:本文为博主原创文章,遵循CC 4.0 ...
- 微信小程序路径表达式解析规则
小程序 setData 方法支持路径表达式来设置属性,例如 setData({"x.y.z": 1}). 微信官方没有公布路径表达式的语法规则及解析规则,本文所描述的路径表达式解析 ...
- docker封装redis镜像
一.概述 线上使用的redis版本为 3.2.13,但是dockerhub没有此版本的镜像.只有3.2.12但是默认的镜像启动时,是没有redis.conf的,如果需要加配置,需要自己定义配置文件. ...
- c#中关于@的作用
参考链接:https://www.cnblogs.com/linkbiz/p/6380814.html
- SQL server数据库创建代码,filegroup文件组修改,
以下示例在 SQL Server 实例上创建了一个数据库.该数据库包括一个主数据文件.一个用户定义文件组和一个日志文件.主数据文件在主文件组中,而用户定义文件组包含两个次要数据文件.ALTER DAT ...