标签:tar 代码 distance algorithm ORC 暴力 ack cto tin
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 2e5+9;
int a[N];
int cnt[N];
int tem[N];
vector<int>G[N];
int dp[N][555];
int n, k;
ll ans = 0;
void dfs(int u, int fa) {
dp[u][0] = 1;
for (auto v:G[u]) {
if (v == fa)continue;
dfs(v, u);
for (int i = 0; i <= k; i ++) {
ans += (ll)dp[v][i] * dp[u][k-i-1];
}
for (int i = 0; i <= k; i ++) {
dp[u][i + 1] += dp[v][i];
}
}
}
void solve() {
cin >> n >> k;
for (int i = 1; i < n; i ++) {
int u, v;cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, -1);
}
int main() {
//ios::sync_with_stdio(0);
//freopen("powers.in", "r", stdin);
//freopen("output.out","w", stdout);
//gogo();
int t=1;//cin >> t;
while (t--) {
solve();
cout << ans << endl;
}
return 0;
}
标签:tar 代码 distance algorithm ORC 暴力 ack cto tin
原文地址:https://www.cnblogs.com/Xiao-yan/p/14767122.html