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 ...
随机推荐
- Comet OJ - Contest #1 C 复读游戏(状态压缩)
题意 https://www.cometoj.com/contest/35/problem/C?problem_id=1498 思路 这题要用到一种比较小众的状压方法(没见过的话可能一时比较难想到). ...
- Gamma阶段第九次scrum meeting
每日任务内容 队员 昨日完成任务 明日要完成的任务 张圆宁 #91 用户体验与优化https://github.com/rRetr0Git/rateMyCourse/issues/91(持续完成) # ...
- [Gamma]阶段测试报告
后端测试 我们进行了覆盖性测试,覆盖率达到77%. Beta阶段发现的Bug 项目显示的图片错误 无法使用搜索框 发布实验室项目的按钮点击无法跳转 连续点击发帖按钮可能发出多个相同的帖子 不需要点击我 ...
- docker 镜像加速,修改为阿里云镜像
首先访问 登录阿里云 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors,会获取专属的镜像地址 centos用户执行下列操作即可 s ...
- git安装和使用配置
1.简介 Git是一个开源的分布式版本控制系统,能用于快速高效地处理任何或小或大的项目,它是Linus Torvalds为了帮助管理Linux内核开发而开发的一个源码开放的版本控制软件. 2.Linu ...
- 【Appium + Python + WebviewH5】之微信小程序自动化测试
进行调试,打开X5: http://debugmm.qq.com/?forcex5=true http://debugx5.qq.com http://debugtbs.qq.com 一般前两个就可以 ...
- RuntimeError: Model class myapp.models.Test doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
没有添加子应用在settings里面!
- yum 多线程插件,apt多线程插件
1.安装yum-axelget插件,默认 yum使用单线程下载,安装该插件后,会使用多线程下载. yum -y install yum-axelget 2. apt-fast安装 https://gi ...
- 一段代码看 Java 引用类型
Java 中的操作数(不知道叫什么,相对于 bytecode 而言,类似 CPU 的操作码和操作数)分为值类型和引用类型: 值类型就是直接存储最终数值的,如 char, int, float, dou ...
- Java之四大元注解@Target、@Retention、@Documented、@Inherited
什么叫做元注解?? ==>用于注解[注释]的注解就叫做元注解 注解叫做:元数据,标签,注释 元注解[数据]--->注解--->标记代码 1.@Target : ...