結果
問題 |
No.1227 I hate ThREE
|
ユーザー |
|
提出日時 | 2020-09-12 01:12:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,337 bytes |
コンパイル時間 | 3,767 ms |
コンパイル使用メモリ | 194,792 KB |
最終ジャッジ日時 | 2025-01-14 12:41:17 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d%d", &n, &C); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d%d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> const int maxn = 1e3 + 3; using ll = long long; const ll mo = 1e9 + 7; int n, C, p[maxn]; std::vector<int> E[maxn]; ll dp[maxn][maxn * 3 * 2 + 3]; void dfs(int u) { for(int i = 1; i <= C && i <= n * 3 * 2 + 2; ++i) { dp[u][i] = 1; } for(auto &&v : E[u]) { if(v == p[u]) continue; p[v] = u; dfs(v); for(int i = 1; i <= C && i <= n * 3 * 2 + 2; ++i) { ll wu = (i - 3 >= 1) ? dp[v][i - 3] : 0ll; ll wv = (i + 3 <= C && i + 3 <= n * 3 * 2 + 2) ? dp[v][i + 3] : 0ll; dp[u][i] = dp[u][i] * ((wu + wv) % mo) % mo; } } } int main() { scanf("%d%d", &n, &C); for(int i = 0; i < n - 1; ++i) { int u, v; scanf("%d%d", &u, &v); E[u].push_back(v); E[v].push_back(u); } dfs(1); ll ans = 0; if(C > n * 3 * 2 + 2) { for(int i = 1; i <= n * 3; ++i) { ans = (ans + dp[1][i]) % mo; } for(int i = 1; i <= n * 3; ++i) { ans = (ans + dp[1][n * 3 * 2 + 2 - i + 1]) % mo; } ans = (ans + dp[1][n * 3 + 1] * (C - n * 3 * 2) % mo) % mo; } else { for(int i = 1; i <= C; ++i) { ans = (ans + dp[1][i]) % mo; } } printf("%lld\n", (ans % mo + mo) % mo); return 0; }