更好的阅读体验

Portal

Portal1: Codeforces

Portal2: Luogu

Description

You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them.

Input

The first line of the input contains a single integer \(N (3 \le N \le 10)\).

The following \(N\) lines each contain \(N\) space-separated integers. jth integer in ith line aij is the length of the edge that connects vertices \(i\) and \(j\). \(a_{ij} = a_{ji}, a_{ii} = 0, 1 \le a_{ij} \le 100\) for \(i \ne j\).

Output

Output the maximum length of the shortest path between any pair of vertices in the graph.

Sample Input1

3
0 1 1
1 0 4
1 4 0

Sample Output1

2

Sample Input2

4
0 1 2 3
1 0 4 5
2 4 0 6
3 5 6 0

Sample Output2

5

Hint

You're running short of keywords, so you can't use some of them:

define
do
for
foreach
while
repeat
until
if
then
else
elif
elsif
elseif
case
switch

Solution

这题的\(n\)最大只有\(10\),求的是两点见的最大的最短路,我们直接用Floyd解决。

但这是一道愚人节的题,题目规定我们不能使用一些语法,我们直接可以用这样的形式解决:

#defin\
e ... ...

注意,把for改为大写还是会判错。

Code

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#defin\
e rep fo\
r using namespace std; const int INF = 0x3f3f3f3f, MAXN = 15;
int n, map[MAXN][MAXN];
int main() {
scanf("%d", &n);
rep (int i = 1; i <= n; i++)
rep (int j = 1; j <= n; j++)
scanf("%d", &map[i][j]);
rep (int k = 1; k <= n; k++)
rep (int i = 1; i <= n; i++)
rep (int j = 1; j <= n; j++)
map[i][j] = min(map[i][j], map[i][k] + map[k][j]);//Floyd
int ans = -INF;
rep (int i = 1; i <= n; i++)
rep (int j = 1; j <= n; j++)
ans = max(ans, map[i][j]);
printf("%d\n", ans);
}

『题解』Codeforces656E Out of Controls的更多相关文章

  1. 『题解』洛谷P1063 能量项链

    原文地址 Problem Portal Portal1:Luogu Portal2:LibreOJ Portal3:Vijos Description 在\(Mars\)星球上,每个\(Mars\)人 ...

  2. 『题解』Codeforces1142A The Beatles

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently a Golden Circle of Beetlovers ...

  3. 『题解』Codeforces1142B Lynyrd Skynyrd

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently Lynyrd and Skynyrd went to a ...

  4. 『题解』洛谷P1993 小K的农场

    更好的阅读体验 Portal Portal1: Luogu Description 小\(K\)在\(\mathrm MC\)里面建立很多很多的农场,总共\(n\)个,以至于他自己都忘记了每个农场中种 ...

  5. 『题解』洛谷P2296 寻找道路

    更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 在有向图\(\mathrm G\)中,每条边的长度均为\(1\),现给定起点和终点 ...

  6. 『题解』洛谷P1351 联合权值

    更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 无向连通图\(\mathrm G\)有\(n\)个点,\(n - 1\)条边.点从 ...

  7. 『题解』洛谷P2170 选学霸

    更好的阅读体验 Portal Portal1: Luogu Description 老师想从\(N\)名学生中选\(M\)人当学霸,但有\(K\)对人实力相当,如果实力相当的人中,一部分被选上,另一部 ...

  8. 『题解』洛谷P1083 借教室

    更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Portal3: Vijos Description 在大学期间,经常需要租借教室.大到院系举办活动,小到 ...

  9. 『题解』Codeforces9D How many trees?

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description In one very old text file there was wr ...

随机推荐

  1. Mac 下安装配置MongoDB讲解

    1.访问官网地址是:MongoDB Download Center | MongoDB,一般下载server的Community 版,对于一般开发人员来说已经够用了.   2.点击“DOWNLOAD( ...

  2. MQ相关面试题

    如果你的简历中有写到MQ,那么面试官一般会问到如下几个问题,至少我在面试中经常常被问到,所以今天总结一下,有不对的地方还望多多包涵: 首先第一个问题,为什么要用MQ? 如果这个问题你都没考虑过,那么说 ...

  3. C语言入门-结构类型

    一.声明结构类型 #include <stdio.h> int main(int argc, char const *argv[]) { // 声明结构类型 struct date { i ...

  4. Redis实现分布式文件夹锁

    缘起 最近做一个项目,类似某度云盘,另外附加定制功能,本人负责云盘相关功能实现,这个项目跟云盘不同的是,以项目为分配权限的单位,同一个项目及子目录所有有权限的用户可以同时操作所有文件,这样就很容易出现 ...

  5. postman全局变量设置

    1.点击小齿轮进入到变量添加页面,点击Globals添加全局变量 2.输入变量名称和变量值 3.接口中设置变量

  6. 关于seaJs合并压缩(gulp-seajs-combine )路径与文件ID匹配问题。

    前段时间和有大家介绍过用 gulp-seajs-combine 来打包seaJs文件.大家会发现合并seaJs一个很奇怪的现象,那就是它的 ID和路径匹配原则.使得有些文件已经合并过去了,但还是会提示 ...

  7. vue——父子组件间传值

    (1)父组件给子组件传值(商品详情页): 根据订单类型,判断显示立即购买/立即拼单: 通过props来传递参数 父组件(商品详情页) 父组件调用子组件,在子组件的标签中,通过:数据名称=”数据”的形式 ...

  8. java学习6-java基础类库

    1.与用户互动 2.系统相关 3.常用类 4.日期.时间类

  9. postman使用实例

    以下以一个登录接口为例,介绍一下postman是如何发请求的. 先执行Pre-request Scripts(预处理) - body - tests(进行断言) postman中变量的引用: {{}}

  10. 百万年薪python之路 -- 带颜色的print

    带颜色的print print输出带颜色的方法详解 书写格式: 开头部分:\033[显示方式;前景色;背景色m + 结尾部分:\033[0m ​ 注意:开头部分的三个参数:显示方式,前景色,背景色是可 ...