結果

問題 No.3412 Christmas Tree Coloring
コンテスト
ユーザー Foxy_null
提出日時 2026-01-22 22:46:13
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 763 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,717 ms
コンパイル使用メモリ 275,152 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2026-01-22 22:46:22
合計ジャッジ時間 7,851 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;

#define int long long

// a^nを任意の数字でmodを取りつつ計算するやつ
int modPow(int a, int n, int mod) {
  if (mod == 1) return 0;
  int ret = 1;
  int p = a % mod;

  while (n) {
    if (n & 1) ret = ret * p % mod;
    p = p * p % mod;
    n >>= 1;
  }
  return ret;
}

void testcase() {
  int N;
  cin >> N;

  int a, b;
  vector<int> eda(N, 0);
  for (int i = 1; i < N; i++) {
    cin >> a >> b;
    a--;
    b--;

    eda[a]++;
    eda[b]++;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += modPow(2, eda[i], 998244353);
  }

  cout << ans << '\n';
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  testcase();
  return 0;
}
0