結果

問題 No.2214 Products on Tree
ユーザー KudeKude
提出日時 2023-02-10 23:35:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 3,000 ms
コード長 1,381 bytes
コンパイル時間 3,241 ms
コンパイル使用メモリ 229,628 KB
実行使用メモリ 20,620 KB
最終ジャッジ日時 2023-09-22 00:34:36
合計ジャッジ時間 7,880 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 146 ms
13,532 KB
testcase_04 AC 150 ms
13,868 KB
testcase_05 AC 136 ms
13,208 KB
testcase_06 AC 87 ms
10,132 KB
testcase_07 AC 18 ms
5,088 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 23 ms
5,904 KB
testcase_10 AC 81 ms
9,840 KB
testcase_11 AC 32 ms
6,676 KB
testcase_12 AC 43 ms
7,228 KB
testcase_13 AC 147 ms
13,916 KB
testcase_14 AC 148 ms
14,008 KB
testcase_15 AC 150 ms
13,972 KB
testcase_16 AC 152 ms
14,092 KB
testcase_17 AC 147 ms
14,000 KB
testcase_18 AC 57 ms
11,344 KB
testcase_19 AC 67 ms
11,976 KB
testcase_20 AC 60 ms
11,132 KB
testcase_21 AC 41 ms
9,568 KB
testcase_22 AC 88 ms
14,868 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 50 ms
15,976 KB
testcase_29 AC 16 ms
5,764 KB
testcase_30 AC 50 ms
14,864 KB
testcase_31 AC 92 ms
14,880 KB
testcase_32 AC 85 ms
14,936 KB
testcase_33 AC 69 ms
20,620 KB
testcase_34 AC 68 ms
20,588 KB
testcase_35 AC 115 ms
17,136 KB
testcase_36 AC 114 ms
17,172 KB
testcase_37 AC 63 ms
13,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VVI to(n);
  rep(_, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
  }
  auto dfs = [&](auto self, int u, int p) -> array<mint, 2> {
    array<mint, 2> dp{1, 0};
    for(int v: to[u]) if (v != p) {
      auto d = self(self, v, u);
      array<mint, 2> ndp;
      rep(i, 2) rep(j, 2) if (i + j < 2) ndp[i + j] += dp[i] * d[j];
      dp = ndp;
    }
    dp[1] += dp[0];
    dp[0] += dp[1];
    return dp;
  };
  mint ans = dfs(dfs, 0, -1)[1];
  cout << ans.val() << '\n';
}
0