Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ostream>
- #include <istream>
- #include <math.h>
- #include <conio.h>
- #include <stdio.h>
- using namespace std;
- int main(){
- ifstream in("input.txt");
- ofstream out("output.txt");
- int n, i, j, k;
- in >> n;
- //формируем матрицу смежности
- int ** a;
- a = new int * [n];
- for (i = 0; i <= n - 1; i++)
- a[i] = new int [n];
- //заполняем матрицу смежности
- for (i = 0; i <= n - 1; i++){
- for (j = 0; j <= n - 1; j++){
- in >> a[i][j];
- }
- }
- int s = a[1][2] + a[2][3] + a[3][1];
- for (i = 0; i <= n - 1; i++){
- for (j = 0; j <= n - 1; j++){
- for (k = 0; k <= n - 1; k++){
- if (a[i][j] + a[j][k] + a[k][i] < s) s = a[i][j] + a[j][k] + a[k][i];
- }
- }
- }
- out << s;
- return 0;
- }
Add Comment
Please, Sign In to add comment