#include <string> #include <vector> #include <iostream> using namespace std; int graph[110][110]; int N; int ans; void floyd() { for(int k = 1; k <= N; k++) { for(int i = 1; i <= N; i++) { for(int j = 1; j <= N; j++) { if(graph[i][k] == 1 && graph[k][j] == 1) { graph[i][j] = 1; } } } } } int solution(int n, vector<vector<int>> results) { N = n; for(int i = 0; i < results.size(); i++) { graph[results[i][0]][results[i][1]] = 1; } floyd(); for(int i = 1; i <= N; i++) { int cnt = 0; for(int j = 1; j <= N; j++) { if(graph[i][j] == 1 || graph[j][i] == 1) { cnt++; } } if(cnt == N-1) { ans++; } } return ans; } | cs |
'Programmers > Level 3' 카테고리의 다른 글
[프로그래머스 3] 길찾기 게임 (C/C++) (★★) (0) | 2020.03.05 |
---|---|
[프로그래머스 3] 매칭 점수 (C/C++) (0) | 2020.03.01 |
[프로그래머스 3] 가장 먼 노드 (C/C++) (0) | 2020.02.05 |
[프로그래머스 3] 입국 심사 (C/C++) (0) | 2020.01.27 |
[프로그래머스 3] 예산 (C/C++) (0) | 2020.01.26 |