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 < ...
随机推荐
- D. Eternal Victory(dfs + 思维)
D. Eternal Victory time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- win10专业版安装docker实战
在win10专业版上安装docker 一,下载Docker for Windows Installer.exe 二,在程序面板---程序----程序和功能中找到启动或关闭windows功能,将hype ...
- (十三)C语言之break、continue
- 20165207 Exp9 Web安全基础
目录 20165207 Exp9 Web安全基础 一.实验过程 1.环境配置 2.代理工具burpsuite 2.1 Http proxies -> Use the intercept 3.sq ...
- LeetCode 42. 接雨水(Trapping Rain Water)
题目描述 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水. 上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况 ...
- Async Task Types in C#
Async Task Types in C# Extend async to support task types that match a specific pattern, in addition ...
- Android版本之间的区别
不同版本SDK适配要点 1,指定minSDKVersion与targetSDKVersion 2,运行时获取版本号 3,使用系统内置的主题,会随着版本的更换而自动适配 4,用android提供的注解 ...
- SolrCloud配置
一.简介 Apache Solr是基于Lucene的全文搜索引擎.如何让Solr具有容错性和高可用性,SolrCloud可以帮助我们搭建集群,提供分布式索引,以及自动备份.SolrCloud是Solr ...
- 发布机制-A/B 测试:百科
ylbtech-发布机制-A/B 测试:百科 AB测试是为Web或App界面或流程制作两个(A/B)或多个(A/B/n)版本,在同一时间维度,分别让组成成分相同(相似)的访客群组(目标人群)随机的访问 ...
- GitHub:IBM
ylbtech-GitHub:IBM 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 1. https://github.com/ibm 2. 6.返回顶部 ...