We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://school.programmers.co.kr/learn/courses/30/lessons/49191
import java.util.*; public class Solution { public int solution(int n, int[][] results) { int answer = n; int INF = n * n; // 그래프 초기화 int[][] graph = new int[n][n]; for (int i = 0; i < n; i++) { Arrays.fill(graph[i], INF); graph[i][i] = 0; } // 그래프에 result값 반영 for (int[] result : results) { graph[result[0] - 1][result[1] - 1] = 1; } // ** 플로이드 와샬 알고리즘 ** for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { graph[i][j] = Math.min(graph[i][j], graph[i][k] + graph[k][j]); } } } // answer 만들기 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { continue; } if (graph[i][j] == INF && graph[j][i] == INF) { answer--; break; } } } return answer; } }
참고
https://bellog.tistory.com/174
The text was updated successfully, but these errors were encountered:
No branches or pull requests
[플로이드 와샬(Floyd-Warshall)]
✅ 최단거리 알고리즘
✅ 기본 아이디어
✅ ex1. 순위
https://school.programmers.co.kr/learn/courses/30/lessons/49191
참고
https://bellog.tistory.com/174
The text was updated successfully, but these errors were encountered: