13023:ABCDE

computer_log·2023년 9월 21일
0
post-thumbnail

깊이 까지 도달했다면, 사람 A, B, C, D, E가 존재

1.lev이 해당 n 까지 도달했다면 1 을 출력한다.
2.

#include <iostream>
#include <vector>
using namespace std;
int N, M;
static vector<vector<int>>alist;
int a, b;
static vector<bool>check;
static bool arrive;
void dfs(int lev, int now) {
	if (lev == 5||arrive) {
		arrive = true;
		return;
	}
	for (int i = 0; i < alist[now].size(); i++) {
		int next = alist[now][i];
		if (check[next])continue;
		check[next] = true;
		dfs(lev + 1, next);
		check[next] = false;
	}
}
int main() {

	freopen_s(new FILE*, "input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> N >> M;
	alist.resize(N);
	check.resize(N);
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		alist[a].push_back(b);
		alist[b].push_back(a);
	}
	arrive = false;
	for (int i = 0; i < N; i++) {
		dfs(0, i);
		if (arrive == true) {
			break;
		}
	}
	if (arrive == true)cout << "1";
	else cout << "0";
	return 0;
}

후 삽질하고있었다!!!!!!!!!!!!!!!!!!!!!!!!!!

유니온파인드로 못푸나,,?

profile
computer_log

0개의 댓글