更好的阅读体验

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. 网页布局——float浮动布局

    我的主要参考资料是[Object object]的文章 float 布局应该是目前各大网站用的最多的一种布局方式了,但是也特别复杂,这里详细讲一下 首先,什么是浮动? 浮动元素是脱离文档流的,但不脱离 ...

  2. 部署主从dns

    主机部署:yum安装DNS服务和依赖 [admin@haifly-bj-dns1 ~]$ sudo yum install bind-chroot启动named-chroot服务 [admin@hai ...

  3. JavaScript ES6函数式编程(一):闭包与高阶函数

    函数式编程的历史 函数的第一原则是要小,第二原则则是要更小 -- ROBERT C. MARTIN 解释一下上面那句话,就是我们常说的一个函数只做一件事,比如:将字符串首字母和尾字母都改成大写,我们此 ...

  4. Python中的可变对象与不可变对象、浅拷贝与深拷贝

    Python中的对象分为可变与不可变,有必要了解一下,这会影响到python对象的赋值与拷贝.而拷贝也有深浅之别. 不可变对象 简单说就是某个对象存放在内存中,这块内存中的值是不能改变的,变量指向这块 ...

  5. django渲染高阶

    08.16自我总结 django渲染高阶 一.利用母版渲染 1.创建母版文件 如:stamper.html <!DOCTYPE html> <html lang="en&q ...

  6. npm install bcrypt报错

    gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env va ...

  7. angular之模块开发二

    一.模块化规范 1.服务器端规范 CommonJS--node.js 2.浏览器端规范 AMD--RequireJS 国外相对流行 CMD--SeaJS 国内相对流行 3.模块化框架实现 CMD实现- ...

  8. java类在何时被加载

    我们接着上一章的代码继续来了解一下java类是在什么时候加载的.在开始验证之前,我们现在IDEA做如下配置. -XX:+TraceClassLoading 监控类的加载 我们新建了一个TestCont ...

  9. 再谈 APISIX 高性能实践

    2019 年 8 月 31 日,OpenResty 社区联合又拍云,举办 OpenResty × Open Talk 全国巡回沙龙·成都站,APISIX 主要作者王院生在活动上做了<APISIX ...

  10. Yii 1.1.x 单元测试

    代码若不整洁,只会越来越糟糕:代码写不好,公司要黄是迟早. Yii 的应用有两种,下面记录这两种应用的单元测试方法 webApplication consoleApplication 在protect ...