H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)
题意:
给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环。
思路:
直接6遍 floyd 输出就行了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int inf=(<<);
const int mod=1e9+;
const int N=1e6+;
int n,m; ll dp[][];
int a,b;
ll c;
int main()
{
int T;
scanf("%d", &T);
while (T--) {
memset(dp,0x3f3f3f,sizeof dp); scanf("%d%d",&n,&m);
for (int i = ; i <= m; i++) {
scanf("%d%d%lld",&a,&b,&c);
dp[a][b]=c;
} for (int i = ; i <= ; i++)
{
scanf("%d%d",&a,&b);
for (int l = ; l <n; l++)
for (int j = ; j < n; j++)
for (int k = ; k < n; k++)
dp[j][k]=min(dp[j][l]+dp[l][k],dp[j][k]);
printf("%lld\n",-dp[b][a]);
dp[a][b]=-dp[b][a];
}
}
return ;
}
H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)的更多相关文章
- 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 ...
- 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 ...
- G.Colorful String(The Preliminary Contest for ICPC Asia Xuzhou 2019)
https://nanti.jisuanke.com/t/4 #include <bits/stdc++.h> using namespace std; ,; typedef unsign ...
- E.XKC's basketball team(The Preliminary Contest for ICPC Asia Xuzhou 2019)
https://nanti.jisuanke.com/t/41387 解: 离散化+线段树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); ...
- A.Who is better?(The Preliminary Contest for ICPC Asia Xuzhou 2019)
https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace ...
- The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)
B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std ...
- 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 D. Robots
题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动).问1到n的期望. 解法:因为行动消耗的能量跟行动次数有 ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail
题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...
随机推荐
- codeforces643D
阿狸的基环内向树森林 Background 当阿狸醒来的时候,发现自己处在基环内向森林的深处,阿狸渴望离开这个乌烟瘴气的地方.“明天还有与桃子的约会呢”,阿狸一边走一边说,“可是,这个森林的出口在哪儿 ...
- AcWing:145. 超市(贪心 + 小根堆 or 贪心 + 并查集)
超市里有N件商品,每个商品都有利润pipi和过期时间didi,每天只能卖一件商品,过期商品(即当天di<=0di<=0)不能再卖. 求合理安排每天卖的商品的情况下,可以得到的最大收益是多少 ...
- Jmeter设置成中文
首次启动Jmeter为中文 选择后即变为中文
- C++入门经典-例8.8-虚继承
1:以前讲到从CBird类和CFish类派生子类CWaterBird时,在CWaterBird类中将存在两个CAnimal类的复制.那么如何在派生CWaterBird类时使其只存在一个CAnimal基 ...
- Java多线程深入理解
在java中要想实现多线程,有两种手段,一种是继续Thread类,另外一种是实现Runable接口. 对于直接继承Thread的类来说,代码大致框架是: ? 1 2 3 4 5 6 7 8 9 10 ...
- centos7编译安装Python 3.6.8 后用pip3出现SSL未配置问题(import ssl失败)解决方法
下载源码编译安装openssl https://www.openssl.org/source/openssl-1.0.2j.tar.gz ./config --prefix=/usr/local/op ...
- spring使用@Async注解异步处理
1. 何为异步调用?在解释异步调用之前,我们先来看同步调用的定义:同步就是整个处理过程顺序执行,当各个过程都执行完毕,并返回结果. 异步调用则是只是发送了调用的指令,调用者无需等待被调用的方法完全执行 ...
- JS进阶学习<一>
一:区分大小写: 1. JS是区分大小写的,如:classname和ClassName是不一样的.同时注意方法.属性.变量等的大小写吆. 2. JS中的字符.符号等一定要在英文状态下输入吆. 二:变量 ...
- 基于.net 4.0框架的Cipher演示程序
using System.Text; namespace Cipher.Algorithm { static class Caesar { static public string Encrypt(s ...
- 反爬虫2(代理ip)
在进行爬虫访问时,被访问主机除了会校验访问身份,还会校验访问者的ip, 当短时间同ip大量访问时,主机有可能会拒绝 返回,所以就现需要代理ip, 百度中可以获取到大量的免费的代理ip(ps:注意在访问 ...