Cod sursa(job #2939549)

Utilizator AztecaVlad Tutunaru 2 Azteca Data 13 noiembrie 2022 21:30:03
Problema Colorare3 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("colorare3.in");
ofstream fout("colorare3.out");

typedef long long ll;
const int N = (int) 1e5 + 7;
const int M = (int) 1e9 + 7;
int f[N];

int mul(int a, int b) {
  return (ll) a * b % M;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n, k;
  fin >> n >> k;
  for (int i = 1; i < n; i++) {
    int u, v;
    fin >> u >> v;
    f[u]++;
    f[v]++;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int j = 0;
    while (f[i] > 1) {
      ans = mul(ans, (k - j + 1));
      f[i]--;
      j++;
    }
  }
  fout << ans;
  return 0;
}