#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 500;
long long dp[maxn][6];
long long dpp[maxn][6];
long long ans = 0;
vector<long long> ger[maxn];
bool vis[maxn];
long long k;
void dfs(long long a) {
  vis[a] = 1;
  long long par = -1;
  for (long long i = 0; i < ger[a].size(); i++) {
    long long v = ger[a][i];
    if (vis[v] == 0) {
      dfs(v);
    } else {
      par = v;
    }
  }
  for (long long i = 0; i < ger[a].size(); i++) {
    long long v = ger[a][i];
    if (v != par) {
      for (long long j = 1; j <= k; j++) {
        for (long long t = 1; t <= k; t++) {
          if (t + j + 1 <= k) {
            ans += dpp[a][t] * dp[v][j];
            ans += dp[a][t] * dpp[v][j];
            ans -= dpp[a][t] * dpp[v][j];
          } else if (j != k || t != k) {
            ans += dpp[a][t] * dp[v][j];
            ans += dp[a][t] * dpp[v][j];
          } else {
            ans += dpp[a][t] * dp[v][j];
            ans += dp[a][t] * dpp[v][j];
            ans += dpp[a][t] * dpp[v][j];
          }
        }
      }
      for (long long j = 1; j <= k; j++) {
        ans += dp[v][j];
      }
      ans += dpp[v][k];
      for (long long j = 2; j <= k; j++) {
        dp[a][j] += dp[v][j - 1];
        dpp[a][j] += dpp[v][j - 1];
      }
      dpp[a][1] += dpp[v][k];
      dp[a][1] += dp[v][k] + dpp[v][k];
    }
  }
  dpp[a][k]++;
}
int main() {
  long long n;
  cin >> n >> k;
  for (long long i = 1; i < n; i++) {
    long long v, u;
    cin >> v >> u;
    u--;
    v--;
    ger[u].push_back(v);
    ger[v].push_back(u);
  }
  dfs(0);
  cout << ans;
}
