April Fools Day Contest 2016 E. Out of Controls

E. Out of Controls

题目连接:

http://www.codeforces.com/contest/656/problem/E

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 ≤ N ≤ 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. aij = aji, aii = 0, 1 ≤ aij ≤ 100 for i ≠ j.

Output

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

Sample Input

3

0 1 1

1 0 4

1 4 0

Sample Output

2

Hint

题意

给你一个邻接矩阵,然后让你输出其中最大的最短路是多少

但是你不能使用

define

do

for

foreach

while

repeat

until

if

then

else

elif

elsif

elseif

case

switch

这些函数名字

题解:

可以用三目运算符嘛,然后递归的去做就好了。

代码

#include<bits/stdc++.h>
using namespace std; int a[15][15];
int res;
int n;
int get(int x,int y)
{
cin>>a[x][y];
return y==n?(x==n?1:get(x+1,1)):get(x,y+1);
}
int geta(int x,int y)
{
res=max(res,a[x][y]);
return y==n?(x==n?1:geta(x+1,1)):geta(x,y+1);
}
int flyod(int x,int y,int k)
{
a[x][y]=min(a[x][y],a[x][k]+a[k][y]);
y++;
y==n+1?(x++,y=1):0;
x==n+1?(x=1,k++):0;
k<=n?flyod(x,y,k):0;
}
int main()
{
cin>>n;
get(1,1);
flyod(1,1,1);
geta(1,1);
cout<<res<<endl;
}
上一篇:[LeetCode] 26. 删除排序数组中的重复项


下一篇:python接口自动化测试二十三:文件上传