Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<cstdlib>
- #define long long long
- using namespace std;
- long n, m, ans = 0;
- vector<vector<long>> edg(10);
- vector<bool> tic(10, 0);
- void dfs(long i, long cnt)
- {
- if (cnt == n){
- ++ans;
- return;
- }
- for (const auto &j : edg[i])
- if (!tic[j]){
- tic[j] = 1;
- dfs(j, cnt+1);
- tic[j] = 0;
- }
- }
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("duongdi.inp", "r", stdin);
- cin >> n >> m;
- while (m--){
- long x, y;
- cin >> x >> y;
- edg[x].push_back(y);
- edg[y].push_back(x);
- }
- tic[1] = 1;
- dfs(1, 1);
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment