Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 우선순위큐
- 코딩테스트연습
- 스택
- 정렬
- vector
- dfs
- Dijkstra
- substr
- 문자열
- 리시프
- 동적계획법
- 코테
- 알고리즘
- set
- String
- MAP
- 최대공약수
- 참고 문헌 : MACHINE LEARNING 기계학습 _ 오일석
- 백준
- 다이나믹프로그래밍
- MySQL
- 플로이드와샬
- 다익스트라
- unordered_map
- 시스템콜
- DP
- sql고득점kit
- 코테준비
- C++
- 프로그래머스
Archives
- Today
- Total
YeJin's Footsteps
네트워크 본문
문제 링크
https://programmers.co.kr/learn/courses/30/lessons/43162
코딩테스트 연습 - 네트워크
네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있
programmers.co.kr
문제 풀이 코드
#include <string>
#include <vector>
using namespace std;
bool visited[201];
void dfs(int n, vector<vector<int>> computers){
visited[n]=true;
for(int i=0; i<computers.size(); i++){
if(n==i) continue;
else if(computers[n][i]){
if(!visited[i]) dfs(i,computers);
else continue;
}
}
return;
}
int solution(int n, vector<vector<int>> computers) {
int answer = 0;
for(int i=0; i<n; i++){
if(!visited[i]){
answer++;
dfs(i, computers);
}
else continue;
}
return answer;
}
Solution 함수에서 dfs 함수를 반복문을 통해 호출하는데, 이부분 때문에 1시간을 날렸다. XX..
이유는 dfs(i, computers)가 아닌 dfs(0, computers)를 반복해서 호출했기 때문이다...
멍청이......
