結果

問題 No.1227 I hate ThREE
ユーザー 👑 jupirojupiro
提出日時 2020-09-13 20:37:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 2,865 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 141,420 KB
実行使用メモリ 81,408 KB
最終ジャッジ日時 2023-09-03 23:56:08
合計ジャッジ時間 5,132 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 5 ms
6,064 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 14 ms
12,232 KB
testcase_09 AC 11 ms
10,140 KB
testcase_10 AC 7 ms
7,244 KB
testcase_11 AC 89 ms
74,192 KB
testcase_12 AC 98 ms
81,372 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 10 ms
9,704 KB
testcase_15 AC 16 ms
14,624 KB
testcase_16 AC 38 ms
31,528 KB
testcase_17 AC 23 ms
19,380 KB
testcase_18 AC 53 ms
44,444 KB
testcase_19 AC 42 ms
34,692 KB
testcase_20 AC 58 ms
48,188 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 43 ms
36,016 KB
testcase_23 AC 97 ms
78,248 KB
testcase_24 AC 100 ms
81,180 KB
testcase_25 AC 100 ms
81,408 KB
testcase_26 AC 90 ms
74,028 KB
testcase_27 AC 96 ms
78,500 KB
testcase_28 AC 98 ms
80,696 KB
testcase_29 AC 98 ms
80,716 KB
testcase_30 AC 93 ms
75,892 KB
testcase_31 AC 92 ms
75,604 KB
testcase_32 AC 97 ms
80,116 KB
testcase_33 AC 91 ms
75,248 KB
testcase_34 AC 94 ms
77,708 KB
testcase_35 AC 90 ms
74,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
constexpr int MAX = 5000000;
struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int n, C; cin >> n >> C;
	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	int cnt = 0;
	if (n * 10 < C) {
		cnt = C - n * 10;
		C = n * 10;
	}
	vector<vector<mint>> dp(n, vector<mint>(C));
	auto dfs = [&](auto&& f, int cur, int pre)->void {
		for (int i = 0; i < C; i++) {
			dp[cur][i] = 1;
		}
		for (auto nxt : g[cur]) {
			if (nxt == pre) continue;
			f(f, nxt, cur);
			for (int i = 0; i < C; i++) {
				mint cnt = 0;
				if (i - 3 >= 0) {
					cnt += dp[nxt][i - 3];
				}
				if (i + 3 < C) {
					cnt += dp[nxt][i + 3];
				}
				dp[cur][i] *= cnt;
			}
		}
	};
	dfs(dfs, 0, -1);
	mint res = 0;
	for (int i = 0; i < C; i++) res += dp[0][i];
	res += mint(2).pow(n - 1) * cnt;
	cout << res.x << "\n";
	return 0;
}
0