Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <cstring>
- #include <deque>
- #include <stack>
- #include <stdio.h>
- #include <map>
- #include <set>
- #include <time.h>
- #include <string>
- #include <fstream>
- #include <queue>
- #include <bitset>
- #include <cstdlib>
- #include <assert.h>
- #define X first
- #define Y second
- #define mp make_pair
- #define pb push_back
- #define pdd pair<double,double>
- #define pii pair<ll,ll>
- #define PI 3.14159265358979323846
- #define MOD 1000000007
- #define MOD2 1000000009
- #define INF ((ll)1e+18)
- #define x1 fldgjdflgjhrthrl
- #define x2 fldgjdflgrtyrtyjl
- #define y1 fldggfhfghjdflgjl
- #define y2 ffgfldgjdflgjl
- #define N 100500
- #define SUM 23423
- #define MAG 10678787
- #define OPEN 0
- #define CLOSE 1
- typedef long long ll;
- typedef long double ld;
- using namespace std;
- ll i,j,n,k,l,m,tot, flag,r,z, K,x1,y1,x2,y2,x3,y3,x,y,h,num,h2,timer,cur_x,cur_y;
- vector<ll> g[100500];
- vector<ll> f;
- set<vector<ll> > ff;
- ll a[100500], b[100500], c[100500];
- void dfs(ll v, ll lvl, ll p)
- {
- a[v] = 1;
- if (g[v].size() <= 1)
- c[v] = 1;
- if (lvl == m)
- {
- c[v] = 1;
- return;
- }
- ll k = 0;
- for (int i = 0; i < g[v].size(); i++)
- {
- int to = g[v][i];
- if (to != p)
- {
- k++;
- dfs(to, lvl+1, v);
- }
- }
- if (k == 0)
- c[v] = 1;
- }
- void magical_dfs(ll v, ll lvl, ll p)
- {
- if (c[v] == 0)
- c[v] = lvl;
- else
- c[v] = min(c[v], lvl);
- for (int i = 0; i < g[v].size(); i++)
- {
- int to = g[v][i];
- if (to != p && a[to] && (c[to] > lvl+1 || c[to] == 0))
- {
- magical_dfs(to, lvl+1, v);
- }
- }
- }
- ll dfs_hash(ll v, ll p = -1)
- {
- ll sz = 0;
- ll hash = 2347;
- ll m = g[v].size();
- ll b[m+1];
- for (int i = 0; i < g[v].size(); i++)
- {
- ll to = g[v][i];
- if (to != p && a[to])
- b[sz++] = dfs_hash(to, v)*533773;
- }
- sort(b, b+sz);
- for (int i = 0; i < sz; i++)
- hash = (hash*MAG+b[i]);
- return hash;
- }
- int main() {
- //freopen("input.txt","r",stdin);
- //freopen("output.txt","w",stdout);
- cin >> n >> m;
- if (m == 0)
- {
- cout << 1 << endl;
- return 0;
- }
- for (i = 0; i < n-1; i++)
- {
- cin >> x >> y;
- g[x].push_back(y);
- g[y].push_back(x);
- }
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= n; j++)
- a[j] = c[j] = 0;
- dfs(i, 0, -1);
- f.clear();
- for (j = 1; j <= n; j++)
- if (c[j] == 1)
- magical_dfs(j, 1, -1);
- ll max1 = 0;
- for (j = 1; j <= n; j++)
- max1 = max(max1, c[j]);
- for (j = 1; j <= n; j++)
- if (c[j] == max1)
- {
- f.push_back(dfs_hash(j));
- }
- sort(f.begin(), f.end());
- ff.insert(f);
- }
- cout << ff.size() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement