結果

問題 No.3412 Christmas Tree Coloring
コンテスト
ユーザー umezo
提出日時 2025-12-21 21:28:51
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 870 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,030 ms
コンパイル使用メモリ 281,564 KB
実行使用メモリ 17,904 KB
最終ジャッジ日時 2025-12-21 21:28:58
合計ジャッジ時間 5,372 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#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(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
using u128=__int128_t;
using ll=long long;

const int MOD=998244353;
V<int> G[200200];
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  V<ll> P(n);
  P[0]=1;
  for(int i=1;i<n;i++) P[i]=P[i-1]*2%MOD;
  V<ll> A(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--,b--;
    A[a]++,A[b]++;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans=0;
  rep(i,n){
    bool b=false;
    for(auto v:G[i]){
      if(A[v]>1) b=true;
    }
    if(b) ans=(ans+P[A[i]])%MOD;
    else ans=(ans+P[A[i]]-2)%MOD;
  }
  cout<<ans<<endl;
    
  return 0;
}
0