Cod sursa(job #1992042)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 19 iunie 2017 11:04:35
Problema Colorare3 Scor 90
Compilator cpp Status done
Runda Simulare 15b Marime 0.86 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;
bool viz[nmax + 1];
vector< int > g[nmax + 1];

i64 ans;
int aux;

void dfs (int nod, int are_tata) {
    viz[ nod ] = 1;

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

    for (const auto &i : g[ nod ]) {
        if (viz[ i ] == 0) {
            dfs(i, 1);
        }
    }
}

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

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

    ans = 1;
    dfs(1, 0);

    fout << ans << "\n";

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