Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 30010;
- int n, arb, temp = 1, viz[N];
- vector<int> v[N];
- void dfs(int);
- int main()
- {
- cin >> n;
- for(int x, y, i = 1; i <= n; i++)
- {
- cin >> x >> y;
- v[x].push_back(y);
- v[y].push_back(x);
- }
- for(int i = 1; i <= n; i++)
- sort(v[i].begin(), v[i].end());
- dfs(1);
- cout << endl << arb;
- return 0;
- }
- void dfs(int nod)
- {
- cout << temp << ' ';
- viz[nod] = 1;
- vector <int> tempv;
- for(auto it: v[nod])
- {
- if(!viz[it])
- {
- tempv.push_back(it);
- viz[it] = 1;
- temp++;
- if(temp == n)
- arb++;
- }
- }
- for(auto vec: tempv)
- dfs(vec);
- for(auto vec: tempv)
- viz[vec] = 0;
- temp -= tempv.size();
- viz[nod] = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement