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
- ue5
- 재귀
- XR Interaction Toolkit
- 스택
- BFS
- 유니온 파인드
- 구현
- 백트래킹
- 알고리즘
- Unreal Engine 5
- 수학
- c++
- Team Fortress 2
- 자료구조
- 유니티
- 그래프
- 누적 합
- 문자열
- 그리디 알고리즘
- 시뮬레이션
- VR
- 트리
- 정렬
- 다이나믹 프로그래밍
- DFS
- 브루트포스
- 투 포인터
- 다익스트라
- 우선순위 큐
- 백준
Archives
- Today
- Total
1일1알
백준 11403번 경로 찾기 C++ 본문
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;
int n;
vector<vector<int>> graph(101, vector<int>());
vector<bool> visited(101, false);
void Print() {
for (int i = 1; i <= n; i++) {
if (visited[i]) cout << 1 << " ";
else cout << 0 << " ";
}
cout << "\n";
}
void RefreshVisited() {
for (int i = 1; i <= n; i++) {
visited[i] = false;
}
}
void Dfs(int n) {
for (auto a : graph[n]) {
if (visited[a]) continue;
visited[a] = true;
Dfs(a);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int input;
cin >> input;
if (input == 0) continue;
graph[i].push_back(j);
}
}
for (int i = 1; i <= n; i++) {
RefreshVisited();
Dfs(i);
Print();
}
};
'알고리즘' 카테고리의 다른 글
백준 16236번 아기 상어 C++ (0) | 2022.04.07 |
---|---|
백준 1389번 케빈 베이컨의 6단계 법칙 (0) | 2022.04.06 |
백준 2239번 스도쿠 C++ (0) | 2022.04.04 |
백준 15666번 N과 M (12) C++ (0) | 2022.04.02 |
백준 15663번 N과 M (9) C++ (0) | 2022.04.01 |