728x90
https://www.acmicpc.net/problem/13023
++relationDepth ์๋๊ณ relationDepth+1 ์ด ๋ง์!!!!!!!!!!!
#include <iostream>
#include <vector>
using namespace std;
const int MAX_SIZE = 2001;
vector<int> graph[MAX_SIZE];
bool visited[MAX_SIZE];
int answer;
void DFS(int person, int relationDepth);
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int personNum, relationNum, person1, person2;
cin >> personNum >> relationNum;
for (int i = 0; i < relationNum; i++) {
cin >> person1 >> person2;
graph[person1].push_back(person2);
graph[person2].push_back(person1);
}
for (int i = 0; i < personNum; i++) {
for (int j = 0; j < personNum; j++) visited[j] = false;
DFS(i, 0);
if (answer) break;
}
cout << answer << "\n";
return 0;
}
void DFS(int person, int relationDepth) {
if (relationDepth == 4) {
answer = 1;
return;
}
visited[person] = true;
for (int i = 0; i < graph[person].size(); i++) {
if (!visited[graph[person][i]]) {
DFS(graph[person][i], relationDepth+1);
}
}
visited[graph[person][i]] = false;
}
728x90
'๐ Coding Test Study > Algorithm Problem' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++][Programmers][์ ๋ ฌ] ๊ฐ์ฅ ํฐ ์ (1) | 2023.04.19 |
---|---|
[C++][Programmers][์ ๋ ฌ] K๋ฒ์งธ ์ (0) | 2023.04.19 |
[C++][Beakjoon] 11724๋ฒ ์ฐ๊ฒฐ์์ (0) | 2022.05.10 |
[C++][Baekjoon][๋นํธ๋ง์คํฌ] 11723๋ฒ ์งํฉ (0) | 2022.05.08 |
[C++][Baekjoon] 10971๋ฒ ์ธํ์ ์ํ2 (0) | 2022.05.08 |