题意:

给出一个有向图,再给出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)的更多相关文章

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

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

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

  4. 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); ...

  5. A.Who is better?(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace ...

  6. The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)

    B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std ...

  7. The Preliminary Contest for ICPC Asia Nanjing 2019

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

  8. The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots

    题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动).问1到n的期望. 解法:因为行动消耗的能量跟行动次数有 ...

  9. The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail

    题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...

随机推荐

  1. String,权限修饰符,方法,集合

    String String str1 = "dashu"; String str2 = "dashu"; String string = new String( ...

  2. ERROR: virtualenvwrapper could not find virtualenv in your path

    环境: Ubuntu 18.04 Python3 使用pip3安装virtualenv和virtualenvwrapper两个包,ubuntu18.04中,用户使用pip安装的包在~/.local/下 ...

  3. JavaWeb-SpringSecurity在数据库中查询登陆用户

    系列博文 项目已上传至guthub 传送门 JavaWeb-SpringSecurity初认识 传送门 JavaWeb-SpringSecurity在数据库中查询登陆用户 传送门 JavaWeb-Sp ...

  4. Codeforces Round #567 (Div. 2) E2 A Story of One Country (Hard)

    https://codeforces.com/contest/1181/problem/E2 想到了划分的方法跟题解一样,但是没理清楚复杂度,很难受. 看了题解觉得很有道理,还是自己太菜了. 然后直接 ...

  5. Linux 常用命令之df du

    1.du 命令:显示每个文件或目录的磁盘使用空间 1) du -h --max-depth [root@ip101 app]# pwd /opt/app [root@ip101 app]# du -h ...

  6. docker Swarm mode集群

    基本概念 Swarm 是使用 SwarmKit 构建的 Docker 引擎内置(原生)的集群管理和编排工具. 使用 Swarm 集群之前需要了解以下几个概念. 节点 运行 Docker 的主机可以主动 ...

  7. For 循环 kotlin(10)

    For 循环 for 循环可以对任何提供迭代器(iterator) 的对象进行遍历,语法如下: for (item in collection) print(item) 循环体可以是一个代码块. fo ...

  8. mongodb 操作笔记

    切换库:use 库名 显示所有的数据库:show dbs 创建集合:db.createCollection("collection_name",{capped:true,size: ...

  9. System 源码阅读

    System 属性说明 /** * System 类包含了几个有用的字段和方法,并且不能被实例化. * * @author unascribed * @since 1.0 */ public fina ...

  10. 大数相乘 java

    <pre name="code" class="java">package bigMultiply; import java.math.BigInt ...