Cod sursa(job #1992043)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 19 iunie 2017 11:06:56
Problema Colorare3 Scor 100
Compilator cpp Status done
Runda Simulare 15b Marime 0.73 kb
#include <fstream>
#include <vector>

using namespace std;

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

typedef long long i64;

const int nmax = 1e5;
const int mod = 1e9 + 7;

int k;
int g[nmax + 1];

i64 ans;
int aux;

int main() {
    int n;
    fin >> n >> k;

    for (int i = 1; i <= n - 1; ++ i) {
        int x, y;
        fin >> x >> y;
        ++ g[ x ]; ++ g[ y ];
    }

    ans = 1;
    for (int i = 1; i <= n; ++ i) {
        int are_tata = 1;
        if (i == 1) are_tata = 0;

        aux = g[ i ] - are_tata;
        for (int j = k - are_tata - aux + 1; j <= k - are_tata; ++ j) {
            ans = ans * j % mod;
        }
    }

    fout << ans << "\n";

    fin.close();
    fout.close();
    return 0;
}