結果
問題 |
No.1227 I hate ThREE
|
ユーザー |
![]() |
提出日時 | 2020-09-11 23:16:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,431 bytes |
コンパイル時間 | 1,827 ms |
コンパイル使用メモリ | 176,992 KB |
実行使用メモリ | 814,828 KB |
最終ジャッジ日時 | 2024-12-27 20:04:03 |
合計ジャッジ時間 | 22,540 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 RE * 15 MLE * 14 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; #define MOD 1000000007 //#define MOD 998244353 struct mint { int i; mint() : i(0) {} mint(int x) { i = int(x % MOD); if (i < 0) i += MOD; } template<class T> mint(T x) { i = int(x % MOD); if (i < 0) i += MOD; } mint operator+(const mint x) const {return i + x.i;} mint operator-(const mint x) const {return i - x.i;} mint operator*(const mint x) const {return (long long)i * x.i;} mint operator/(const mint x) const {return (long long)i * x.pow(MOD - 2).i;} mint inv() {return pow(MOD - 2);} template<class T> mint pow(T p) const { long long r = 1; long long t = i; for(; p > 0; p >>= 1) { if (p & 1) r = r * t % MOD; t = t * t % MOD; } return r; } template<class T1, class T2> static mint pow(T1 a, T2 b) { long long r = 1; long long t = (long long)(a % MOD); for(; b > 0; b >>= 1) { if (b & 1) r = r * t % MOD; t = t * t % MOD; } return r; } mint& operator+=(const mint x) { i = (i + x.i) % MOD; return *this; } mint& operator-=(const mint x) { i = i - x.i; if (i < 0) i += MOD; return *this; } mint& operator*=(const mint x) { i = (int)((long long)i * x.i % MOD); return *this; } mint& operator/=(const mint x) { i = (long long)i * x.pow(MOD - 2).i % MOD; return *this; } }; std::ostream& operator<<(std::ostream& os, const mint& m) { return os << m.i; } VVI to; int n, c; vector<mint> dfs(int u, int p=-1) { vector<mint> dp(c + 1); vector<vector<mint>> cdp; for(int v: to[u]) { if (v == p) continue; cdp.push_back(dfs(v, u)); } for(int i = 1; i <= c; i++) { mint t = 1; for(auto& d: cdp) { mint acc = 0; if (i - 3 >= 1) acc += d[i-3]; if (i + 3 <= c) acc += d[i+3]; t *= acc; } dp[i] = t; } return dp; } int main() { cin >> n >> c; to.resize(n); rep(i, n-1) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } auto a = dfs(0); mint ans = 0; for(int i = 1; i <= c; i++) { ans += a[i]; } cout << ans << endl; }