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 |
Tags
- 백트래킹
- BFS
- VR
- 재귀
- 알고리즘
- 브루트포스
- c++
- 자료구조
- 투 포인터
- 그리디 알고리즘
- 그래프
- 수학
- 유니온 파인드
- 누적 합
- 시뮬레이션
- 백준
- ue5
- 정렬
- 문자열
- 스택
- XR Interaction Toolkit
- 트리
- DFS
- 우선순위 큐
- 다익스트라
- 구현
- 유니티
- 다이나믹 프로그래밍
- Team Fortress 2
- Unreal Engine 5
Archives
- Today
- Total
1일1알
백준 13023번 ABCDE C++ 본문
서로 다른 5명이 이어져 있으면 된다.
dfs로 문제를 해결하였는데, 처음에 방문 표시를 엉뚱한 곳에다 해서 시간이 좀 걸렸다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
bool isAns = false;
vector<vector<int>> v(2001, vector<int>());
vector<bool> visited(2001, false);
void Dfs(int n, int cnt) {
if (cnt == 4) {
isAns = true;
return;
}
visited[n] = true;
for (int i = 0; i < v[n].size(); i++) {
if (!visited[v[n][i]]) {
Dfs(v[n][i], cnt + 1);
}
}
visited[n] = false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
int ans = 0;
for (int i = 0; i < n; i++) {
Dfs(i, 0);
if (isAns) {
ans = 1;
break;
}
}
cout<<ans;
};
'알고리즘' 카테고리의 다른 글
백준 6593번 상범 빌딩 C++ (0) | 2022.03.16 |
---|---|
백준 9084번 동전 C++ (0) | 2022.03.15 |
백준 14226번 이모티콘 C++ (0) | 2022.03.13 |
백준 2631번 줄세우기 C++ (0) | 2022.03.12 |
백준 4158번 CD C++ (0) | 2022.03.11 |