문제 출처 : https://www.acmicpc.net/problem/13023
<c++코드>
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include<iostream>
#include<vector>
using namespace std;
vector<int> a[2001];
bool v[2001];
int n,m;
bool anwer;
void dfs(int cnt,int x)
{
if(cnt==5)
{
anwer=true;
return ;
}
v[x]=true;
for(int i=0;i<a[x].size();i++)
{
int y=a[x][i];
if(!v[y])
{
dfs(cnt+1,y);
v[y]=false;
}
}
v[x]=false;
}
int main(void){
cin>>n>>m;
for(int i=0;i<m;i++)
{
int q,w;
cin>>q>>w;
a[q].push_back(w);
a[w].push_back(q);
}
bool find=false;
for(int i=0;i<=n-1;i++)
{ dfs(1,i);
if(anwer)
{
find=true;
break;
}
}
if(find)
{
cout<<"1"<<' ';
}
else
{
cout<<"0"<<' ';
}
return 0;
}
|
cs |
'백준 온라인 저지 > BFS, DFS (그래프)' 카테고리의 다른 글
11724번_연결 요소의 개수(Dfs,Bfs) (0) | 2019.11.27 |
---|---|
2667번_단지번호붙이기(Bfs) (0) | 2019.11.26 |
2178번_미로탐색(Bfs) (0) | 2019.11.26 |
7562번_나이트의 이동(Bfs)_ 아직 (0) | 2019.11.26 |
4963번_섬의 개수(Dfs,Bfs) (0) | 2019.11.26 |