#include <bits/stdc++.h>

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

class graph {
private:
    const size_t count_nodes;
    const bool is_directed;
public:
    vector<size_t> *edges;
    graph(size_t count_nodes, bool is_directed = true) : count_nodes(count_nodes), is_directed(is_directed) {
            edges = new vector<size_t>[count_nodes];
        }
    ~graph() {
        delete [] edges;
    }
    size_t size() const {
        return count_nodes;
    }
    void make_edge(size_t u, size_t v) {
        edges[u].push_back(v);
        if (!is_directed) {
            edges[v].push_back(u);
        }
    }
};

template <class T, T M>
class modulo {
public:
    T data;

    modulo(T data = 0) : data(data % M) {
    }

    modulo operator+(const modulo &x) const {
        return modulo(data + x.data);
    }

    modulo operator-(const modulo &x) const {
        return modulo(data + (M - x.data));
    }

    modulo operator*(const modulo &x) const {
        return modulo(data * x.data);
    }

    modulo operator/(const modulo &x) const {
        return modulo(data * x.inv().data);
    }

    modulo operator+=(const modulo &x) {
        data = (data + x.data) % M;
    }

    modulo operator-=(const modulo &x) {
        data = (data + (M - x.data)) % M;
    }

    modulo operator*=(const modulo &x) {
        data = (data * x.data) % M;
    }

    modulo operator/=(const modulo &x) {
        data = (data * x.inv().data) % M;
    }

    modulo inv() const {
        return _pow(M - 2);
    }

    template <class Integer>
    modulo operator^(Integer n) const {
        if (n >= 0) {
            return _pow(n);
        } else {
            return _pow(M - 1 - (-n) % (M - 1));
        }
    }

    friend std::ostream& operator<<(std::ostream &os, const modulo &x) {
        os << x.data;
        return os;
    }

private:
    template <class NonNegativeInteger>
    modulo _pow(NonNegativeInteger n) const {
        modulo result(1);
        modulo x(*this);
        while (n) {
            if (n & 1) {
                result *= x;
            }
            x *= x;
            n >>= 1;
        }
        return result;
    }
};

using mod = modulo<ll, MOD>;

mod solve(const graph &g, ll N, ll K) {
    int deg_max = 0;
    REP(i, N) {
        amax(deg_max, g.edges[i].size());
    }
    PRINT(deg_max);
    if (deg_max + 1 > K) {
        return 0;
    }

    int n = max(N, K);
    vector<mod> factorial(n + 1), inv_factorial(n + 1);
    factorial[0] = 1;
    for (int i = 1; i <= n; ++i) {
        factorial[i] = mod(i) * factorial[i - 1];
    }
    inv_factorial[n] = factorial[n].inv();
    for (int i = n; i > 0; --i) {
        inv_factorial[i - 1] = mod(i) * inv_factorial[i];
    }
    auto combination = [&](int n, int k) -> mod {
        if (0 <= k && k <= n) {
            return factorial[n] * inv_factorial[k] * inv_factorial[n - k];
        } else {
            return 0;
        }
    };

    vector<int> parent(N, -1);
    parent[0] = 0;

    queue<int> q;
    vector<bool> used(N);
    mod result = factorial[K] * inv_factorial[K - (g.edges[0].size() + 1)];
    PRINT("root");
    PRINT(result);
    q.push(0);
    used[0] = true;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        int deg_u = g.edges[u].size();
        PRINT(u);
        if (u != 0) {
            int deg_p = g.edges[parent[u]].size();
            //result *= combination(K - (deg_p + 1), deg_u - 1);
            int Q = K - (deg_p + 1);
            PRINT(Q);
            PRINT(deg_u - 1);
            if (K - 2 < 0 || K - 2 - (deg_u - 1) < 0) {
                return 0;
            }
            result *= factorial[K - 2] * inv_factorial[K - 2 - (deg_u - 1)];
        }
        PRINT(result);
        for (int v: g.edges[u]) {
            if (!used[v]) {
                q.push(v);
                parent[v] = u;
                used[v] = true;
            }
        }
    }
    return result;
}

int main() {
    ll N, K;
    cin >> N >> K;
    graph g(N, false);
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g.make_edge(a, b);
    }

    cout << solve(g, N, K) << endl;


    return 0;
}



Measured memory_bytes: 8820