View difference between Paste ID: 3tmBwteR and CYvEQck1
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
3
long long inf = 1000000000000LL;
4
5-
long long m[100][100];
5+
long long m[52][52];
6
7
long long min(long long a, long long b)
8
{
9
    return a < b ? a : b;
10
}
11
12
int main()
13
{
14
    int i, j, k, n, from, to;
15
    scanf("%i %i %i", &n, &from, &to);
16
    for(i = 1; i <= n; ++i)
17
    {
18
        for(j = 1; j <= n; ++j)
19
        {
20
            scanf("%lli", &m[i][j]);
21
            if(m[i][j] == -1)
22
            {
23
                m[i][j] = inf;
24
            }
25
        }
26
    }
27
	for(k = 1; k <= n; ++k)
28
    {
29
		for(i = 1; i <= n; ++i)
30
		{
31
			for(j = 1; j <= n; ++j)
32
			{
33
            
34
				m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
35
			}
36
		}
37
	}
38
    printf("%lli\n", m[from][to] == inf ? -1 : m[from][to]);
39
    return 0;
40
}