Submission #6312375


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/














int N, K;
vector<int> E[101010];
//---------------------------------------------------------------------------------------------------
mint dfs(int cu, int pa, int rest) {
	mint res = rest;
	
	int used = 1; // 自分の色
	if (0 < cu) used++; // 親の色
	fore(to, E[cu]) if(to != pa) {
		res *= dfs(to, cu, K - used);
		used++;
	}

	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}

	cout << dfs(0, -1, K) << endl;
}





Submission Info

Submission Time
Task E - Virus Tree 2
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 500
Code Size 3613 Byte
Status AC
Exec Time 46 ms
Memory 11648 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 38
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 2 ms 2688 KB
02.txt AC 2 ms 2688 KB
03.txt AC 2 ms 2688 KB
04.txt AC 2 ms 2688 KB
05.txt AC 2 ms 2688 KB
06.txt AC 2 ms 2688 KB
07.txt AC 2 ms 2688 KB
08.txt AC 2 ms 2688 KB
09.txt AC 2 ms 2688 KB
10.txt AC 8 ms 3200 KB
11.txt AC 13 ms 3712 KB
12.txt AC 30 ms 5248 KB
13.txt AC 35 ms 5632 KB
14.txt AC 36 ms 5632 KB
15.txt AC 35 ms 5632 KB
16.txt AC 35 ms 6012 KB
17.txt AC 34 ms 6012 KB
18.txt AC 33 ms 6012 KB
19.txt AC 27 ms 6136 KB
20.txt AC 27 ms 6136 KB
21.txt AC 27 ms 6136 KB
22.txt AC 34 ms 6012 KB
23.txt AC 33 ms 6012 KB
24.txt AC 33 ms 6012 KB
25.txt AC 27 ms 6136 KB
26.txt AC 27 ms 6136 KB
27.txt AC 28 ms 6136 KB
28.txt AC 34 ms 6012 KB
29.txt AC 34 ms 6012 KB
30.txt AC 34 ms 6012 KB
31.txt AC 27 ms 6136 KB
32.txt AC 27 ms 6136 KB
33.txt AC 28 ms 6136 KB
34.txt AC 41 ms 11648 KB
35.txt AC 46 ms 11520 KB
s1.txt AC 2 ms 2688 KB
s2.txt AC 2 ms 2688 KB
s3.txt AC 2 ms 2688 KB