티스토리 뷰
문제출처 - https://programmers.co.kr/learn/courses/30/lessons/43162
코딩테스트 연습 - 네트워크 | 프로그래머스
네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있을 때 컴퓨터 A와 컴퓨터 C도 간접적으로 연결되어 정보를 교환할 수 있습니다. 따라서 컴퓨터 A, B, C는 모두 같은 네트워크 상에 있다고 할 수 있습니다. 컴퓨터의 개수 n, 연결에 대한 정보가 담긴 2차원 배열 computers가 매개변수로 주어질 때, 네트워크
programmers.co.kr
#include <string>
#include <vector>
using namespace std;
void dfs(int start, vector<vector<int>> computers, bool visit[]) {
visit[start] = true;
printf("%d\n", start);
for(int i=0; i<computers[start].size(); i++) {
if(i == start) continue; // 자기 자신이면 pass
if(computers[start][i] && !visit[i])
dfs(i, computers, visit);
}
}
int solution(int n, vector<vector<int>> computers) {
int answer = 0;
bool visit[n];
fill(visit, visit+n, false);
for(int i=0; i<n; i++) {
if(!visit[i]) {
answer++;
dfs(i, computers, visit);
}
}
return answer;
}
'ALGORITHM > 프로그래머스' 카테고리의 다른 글
[C++]프로그래머스 - 나누어 떨어지는 숫자 배열(level1) (0) | 2019.11.30 |
---|---|
[C++]프로그래머스 - 도둑질(level4) (0) | 2019.11.22 |
[C++]프로그래머스 - 탑(level2) (0) | 2019.11.21 |
[C++]프로그래머스 - 가운데 글자 가져오기(level1) (0) | 2019.11.21 |
[Python]프로그래머스 - K번째수(level1) (0) | 2019.11.17 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 순열
- 정렬
- 재귀
- 백준
- combination
- 구현
- BOJ
- dictionary
- 스택
- 해시
- SWExpert
- hash
- C++
- Python
- 우선순위큐
- 문자열처리
- SW Expert
- 문자열
- 프로그래머스
- 힙
- programmers
- 딕셔너리
- 코딩테스트
- left join
- 괄호
- 2019 Kakao Blind Recruitment
- Permutation
- 2020 KAKAO BLIND RECRUITMENT
- 파이썬
- 완전탐색
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함