题目链接: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的更多相关文章

  1. The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解

    (施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出 ...

  2. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

  3. 计蒜客 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  ...

  4. The Preliminary Contest for ICPC Asia Nanjing 2019

    传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. ...

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

  6. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...

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

  8. H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...

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

随机推荐

  1. java 压缩图片(只缩小体积,不更改图片尺寸)

      1.情景展示 在调用腾讯身份证OCR接口的时候,由于要求图片大小只能限制在1MB以内,这样,就必须使用到图片压缩技术 2.代码展示 /** * 图片处理工具类 * @explain * @auth ...

  2. BeanPostProcessor

    BeanPostProcessor简介 BeanPostProcessor是Spring IOC容器给我们提供的一个扩展接口.接口声明如下: public interface BeanPostProc ...

  3. linux_FHS初遇--良好清晰条理的文件存储习惯

    1. 建议根目录(/)所在分区理论上越小越好,原因一为保证性能,二为易恢复与操作. 2.建议应用程序安装软件不要与根目录放在同一个分区内 3. 建议根目录(/)下应该存在的子目录: /bin 放置在单 ...

  4. odoo前端必填提示

  5. flume到flume消息传递

    环境:两台虚拟机( 每台都有flume) 第一台slave作为消息的产生者 第二台master作为消息的接收者    IP(192.168.83.133) 原理:通过监听slave中文件的变化,获取变 ...

  6. 四元数, Physx中的四元数

    四元数的概念 & 如何使用四元数:  绕V轴旋转 f 角,对应的四元数: q = ( cos(f/2), Vx*sin(f/2), Vy*sin(f/2), Vz*sin(f/2) ) = c ...

  7. spring cloud 客户端负载均衡 - Ribbon

    Spring Cloud Ribbon是一个基于HTTP和TCP的客户端负载均衡工具,基于Netflix Ribbon实现的,Ribbon不像注册中心.网关那样需要单独部署,它是作为一个工具直接集成到 ...

  8. [转] js async await 终极异步解决方案

    阅读目录 回顾 Promise async await 字面理解 async.await 如何执行 await 操作符 总结 既然有了promise 为什么还要有async await ? 当然是pr ...

  9. "类"的讲稿

    -----------------------面向对象基础------------------------------------方法(函数) { (c#p10为主,p27;javap96)+资料,讲 ...

  10. ffmpeg命令参数详解

    ffmpeg命令参数详解 http://linux.51yip.com/search/ffmpeg ffmpeg图片加滤镜效果 参考:https://cloud.tencent.com/develop ...