Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- long long inf = 1000000000000LL;
- long long m[100][100];
- long long min(long long a, long long b)
- {
- return a < b ? a : b;
- }
- int main()
- {
- int i, j, k, n, from, to;
- scanf("%i %i %i", &n, &from, &to);
- for(i = 1; i <= n; ++i)
- {
- for(j = 1; j <= n; ++j)
- {
- scanf("%lli", &m[i][j]);
- if(m[i][j] == -1)
- {
- m[i][j] = inf;
- }
- }
- }
- for(k = 1; k <= n; ++k)
- {
- for(i = 1; i <= n; ++i)
- {
- for(j = 1; j <= n; ++j)
- {
- m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
- }
- }
- }
- printf("%lli\n", m[from][to] == inf ? -1 : m[from][to]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement