Created
October 8, 2020 06:30
-
-
Save MinecraftFuns/d3e3d72d0cb5a24977489dc3078cf00a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \ | |
<< (#x) << ": " << x << std::endl | |
using namespace std; | |
typedef long long ll; | |
typedef unsigned long long ull; | |
typedef pair<int, int> pii; | |
template <typename Tp> | |
inline void read(Tp &x) | |
{ | |
static char c; | |
static bool neg; | |
x = 0, c = getchar(), neg = false; | |
for (; !isdigit(c); c = getchar()) | |
{ | |
if (c == '-') | |
{ | |
neg = true; | |
} | |
} | |
for (; isdigit(c); c = getchar()) | |
{ | |
x = x * 10 + c - '0'; | |
} | |
if (neg) | |
{ | |
x = -x; | |
} | |
} | |
const int N = 4000 + 5; | |
int n, k; | |
int head[N], E = 0; | |
struct Edge | |
{ | |
int to, next; | |
} e[N * 2]; | |
inline void addEdge(int u, int v) | |
{ | |
e[++E] = (Edge){v, head[u]}; | |
head[u] = E; | |
} | |
bitset<N> valid[N]; | |
bitset<N> st; | |
int dep[N]; | |
void dfs(int u, int fa) | |
{ | |
dep[u] = dep[fa] + 1; | |
for (int i = head[u], v; v = e[i].to, i; i = e[i].next) | |
{ | |
if (v != fa) | |
{ | |
dfs(v, u); | |
} | |
} | |
} | |
int main() | |
{ | |
read(n), read(k); | |
for (int i = 1, u, v; i < n; ++i) | |
{ | |
read(u), read(v); | |
addEdge(u, v); | |
addEdge(v, u); | |
} | |
dep[0] = -1; | |
for (int i = 1; i <= n; ++i) | |
{ | |
dfs(i, 0); | |
for (int j = i + 1; j <= n; ++j) | |
{ | |
if (dep[j] <= k) | |
{ | |
valid[i].set(j); | |
} | |
} | |
} | |
ll ans = 0; | |
for (int a = 1; a <= n; ++a) | |
{ | |
for (int c = a + 1; c <= n; ++c) | |
{ | |
if (valid[a].test(c) && a != c) | |
{ | |
ans += (valid[a] & valid[c]).count(); | |
} | |
} | |
} | |
printf("%lld\n", ans * 6); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment