#include <string> #include <vector> using namespace std; int visited[210] = {0}; void DFS(int start, vector<vector<int>> computers) { visited[start] = 1; for(int i = 0; i < computers.size(); i++) { if(start == i) { continue; } if(visited[i] == 0 && computers[start][i] == 1) { visited[i] = 1; DFS(i, computers); } } } int solution(int n, vector<vector<int>> computers) { int answer = 0; for(int i = 0; i < n; i++) { if(visited[i] == 1) { continue; } else { DFS(i, computers); answer++; } } return answer; } | cs |
'Programmers > Level 3' 카테고리의 다른 글
[프로그래머스 3] 여행경로 (C/C++) (★) (0) | 2020.01.09 |
---|---|
[프로그래머스 3] 단어 변환 (C/C++) (0) | 2020.01.09 |
[프로그래머스 3] 이중 우선순위 큐 (C/C++) (0) | 2020.01.08 |
[프로그래머스 3] 베스트 앨범 (C/C++) (★) (0) | 2020.01.07 |
[프로그래머스 3] 하노이의 탑 (C/C++) (0) | 2020.01.04 |