Language: C++

z#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

vector<vector<ll>> G;
ll N,K;

mint dfs(ll n, ll p, ll c){
    if((p!=-1 && G[n].size()==1) || N==1) return mint(K-c);
    mint ans(K-c);
    if(p == -1) c = 1;
    else c = 2;
    for(auto &e : G[n]){
        if(e==p) continue;
        ans *= dfs(e,n,c);
        c++;
    }
    return ans;
}

int main(){
    cin >> N >> K;
    G.resize(N);
    for(int i=0;i<N-1;i++){
        ll a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    cout << dfs(0,-1,0) << endl;
    return 0;
}

Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | z#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'z' does not name a type
    1 | z#include <bits/stdc++.h>
      | ^
a.cc:68:12: error: 'ostream' does not name a type
   68 |     friend ostream& operator<<(ostream& os, const mint& m){
      |            ^~~~~~~
a.cc:74:1: error: 'vector' does not name a type
   74 | vector<vector<ll>> G;
      | ^~~~~~
a.cc: In function 'mint dfs(ll, ll, ll)':
a.cc:78:18: error: 'G' was not declared in this scope
   78 |     if((p!=-1 && G[n].size()==1) || N==1) return mint(K-c);
      |                  ^
a.cc:82:19: error: 'G' was not declared in this scope
   82 |     for(auto &e : G[n]){
      |                   ^
a.cc: In function 'int main()':
a.cc:91:5: error: 'cin' was not declared in this scope
   91 |     cin >> N >> K;
      |     ^~~
a.cc:92:5: error: 'G' was not declared in this scope
   92 |     G.resize(N);
      |     ^
a.cc:99:5: error: 'cout' was not declared in this scope
   99 |     cout << dfs(0,-1,0) << endl;
      |     ^~~~
a.cc:99:28: error: 'endl' was not declared in this scope
   99 |     cout << dfs(0,-1,0) << endl;
      |                            ^~~~