#include <iostream>
#include <vector>
using namespace std;
//그래프의 인접 리스트 표현
vector<vector<int>>adj;
//각 정점을 방문했는지 여부
vector<bool>visited;
//깊이 우선 탐색
void dfs(int here) {
cout << "DFS visits " << here << endl;
visited[here] = true;
//모든 인접 정점을 순회하면서
for (int i = 0; i < adj[here].size(); i++) {
int there = adj[here][i];
//아직 방문한 적이 없다면 방문한다.
if (!visited[there])
dfs(there);
}
//더이상 방문할 정점이 없으니, 재귀 호출을 종료하고 이전 정점으로 돌아간다.
}
void dfsAll() {
//visited를 모두 false로 초기화한다.
visited = vector<bool>(adj.size(), false);
//모든 정점을 순회하면서, 아직 방문한 적 없으면 방문한다.
for (int i = 0; i < adj.size(); i++) {
if (!visited[i])
dfs(i);
}
}
-의존성 그래프
-위상 정렬
-오일러 서킷의 존재 조건
#include <iostream>
#include <vector>
using namespace std;
//그래프의 인접 행렬 표현. adj[i][j]=i와 j사이의 간선의 수
vector<vector<int>> adj;
//무향 그래프의 인접 행렬 adj가 주어질 때 오일러 서킷 계산
//결과로 얻어지는 circuit을 뒤집으면 오일러 서킷이 된다
void getEulerCircuit(int here, vector<int>& circuit) {
for (int there = 0; there < adj[here].size(); there++) {
while (adj[here][there] > 0) {
adj[here][there]--;
adj[there][here]--;
getEulerCircuit(there, circuit);
}
}
//재귀호출이 끝나고 반환 할 때 추가
circuit.push_back(here);
//경로의 끝점부터 역순으로 간선들이 추가
}
-오일러 트레일의 존재 조건