結果

問題 No.3412 Christmas Tree Coloring
コンテスト
ユーザー Falcon_
提出日時 2025-12-19 00:17:46
言語 C++14
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 423 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,466 ms
コンパイル使用メモリ 163,200 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-19 00:17:52
合計ジャッジ時間 4,855 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod=998244353;
signed main(){
	int N;cin>>N;
	vector<int>A(N);
	vector<int>B(N);
	int now=1;
	for(int i=0;i<N-1;i++){
		int a,b;cin>>a>>b;
		a--;
		b--;
		A[a]++;
		A[b]++;
		B[i]=now;
		now*=2;
		now%=mod;
	}
	int ans=0;
	for(int i=0;i<N;i++){
		ans+=(A[i]==N-1?(B[A[i]-1]*2+mod-2)%mod:B[A[i]]);
		//cout<<ans<<endl;
		ans%=mod;
	}
	cout<<ans<<endl;
}
0