-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_13023.cpp
More file actions
64 lines (58 loc) · 1.32 KB
/
bj_13023.cpp
File metadata and controls
64 lines (58 loc) · 1.32 KB
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
60
61
62
63
64
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<vector<int> > relation(20001);
int Count = 5;
int answer = 0;
bool check = false;
void dfs(int str, vector<int> set) {
if(check == true) {
return;
}
if(set.size() == Count) {
answer++;
check = true;
return;
}
for(int i = 0; i < relation[str].size(); i++) {
if(!count(set.begin(), set.end(), relation[str][i])) {
set.push_back(relation[str][i]);
dfs(relation[str][i], set);
set.pop_back();
}
}
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
int N, M;
cin >> N >> M;
for(int i = 0; i<M; i++) {
int a, b;
cin >> a >> b;
if(relation[a].size() == 0) {
vector<int> tt;
tt.assign(1, b);
relation[a] = tt;
}
else {
relation[a].push_back(b);
}
if(relation[b].size() == 0) {
vector<int> tt;
tt.assign(1, a);
relation[b] = tt;
} else {
relation[b].push_back(a);
}
}
for(int i = 0; i< N; i++) {
vector<int> set;
set.push_back(i);
dfs(i, set);
set.pop_back();
}
cout << answer << "\n";
}