Easy Video Explanation 🔥 || Floyd Warshall Algorithm ✅
Intuition\n Describe your first thoughts on how to solve this problem. \nFloyd Warshall Algorithm\n\n# Easy Video Explanation\n\nhttps://youtu.be/dmdnA_yBc90\n\
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFloyd Warshall Algorithm\n\n# ***Easy Video Explanation***\n\nhttps://youtu.be/dmdnA_yBc90\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nOur code calculates the count of pairs of nodes at a specific distance in an undirected graph with \'n\' nodes. It initializes a grid with initial distances between nodes, updates it using Floyd-Warshall algorithm, and then counts pairs at each \n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(N*N*N)\n    \n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(N*N)\n    \n\n# Code\n\n\n```C++ []\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>> grid(n+1, vector<int>(n+1, 1000));\n        \n        for(int j = 1; j < n; j++) {\n            grid[j][j+1] = 1;\n            grid[j+1][j] = 1;\n        }\n        grid[x][y] = 1;\n        grid[y][x] = 1;\n        \n        for(int k = 1; k <= n; k++) {\n            for(int i = 1; i <= n; i++) {\n                for(int j = 1; j <= n; j++) {              \n                   grid[i][j] = min(grid[i][j], grid[i][k] + grid[k][j]);                \n                }\n            }\n        }\n        \n        vector<int> result(n);\n        for(int i = 1; i <= n; i++) {\n            for(int j = 1; j <= n; j++) {\n\n                if(i != j) {\n                    int val = grid[i][j];\n                    result[val-1]++;\n                }\n\n            }\n        }\n        \n        return result;\n        \n    }\n};\n```\n```python []\nclass Solution:\n    def countOfPairs(self, n, x, y):\n        grid = [[1000] * (n + 1) for _ in range(n + 1)]\n\n        for j in range(1, n):\n            grid[j][j+1] = 1\n            grid[j+1][j] = 1\n        grid[x][y] = 1\n        grid[y][x] = 1\n\n        for k in range(1, n + 1):\n            for i in range(1, n + 1):\n                for j in range(1, n + 1):\n                    grid[i][j] = min(grid[i][j], grid[i][k] + grid[k][j])\n\n        result = [0] * n\n        for i in range(1, n + 1):\n            for j in range(1, n + 1):\n                if i != j:\n                    val = grid[i][j]\n                    result[val - 1] += 1\n\n        return result\n\n```\n```Java []\nimport java.util.Arrays;\n\npublic class Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n        int[][] grid = new int[n+1][n+1];\n        for (int[] row : grid) {\n            Arrays.fill(row, 1000);\n        }\n\n        for (int j = 1; j < n; j++) {\n            grid[j][j+1] = 1;\n            grid[j+1][j] = 1;\n        }\n        grid[x][y] = 1;\n        grid[y][x] = 1;\n\n        for (int k = 1; k <= n; k++) {\n            for (int i = 1; i <= n; i++) {\n                for (int j = 1; j <= n; j++) {\n                    grid[i][j] = Math.min(grid[i][j], grid[i][k] + grid[k][j]);\n                }\n            }\n        }\n\n        int[] result = new int[n];\n        for (int i = 1; i <= n; i++) {\n            for (int j = 1; j <= n; j++) {\n                if (i != j) {\n                    int val = grid[i][j];\n                    result[val-1]++;\n                }\n            }\n        }\n\n        return result;\n    }\n}\n\n\n```\n\n# ***If you like the solution Please Upvote and subscribe to my youtube channel***\n***It Motivates me to record more videos***\n\n*Thank you* \uD83D\uDE00
['C++', 'Java', 'Python3']