結果
| 問題 | No.3412 Christmas Tree Coloring |
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2025-12-19 01:18:24 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 137 ms / 2,000 ms |
| コード長 | 575 bytes |
| 記録 | |
| コンパイル時間 | 870 ms |
| コンパイル使用メモリ | 102,664 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-19 01:18:36 |
| 合計ジャッジ時間 | 4,038 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
const int mod = 998244353;
int n;
cin >> n;
vector<int> cnt(n);
for (int i = 1; i < n; ++i)
{
int a, b;
cin >> a >> b;
--a, --b;
++cnt[a];
++cnt[b];
}
vector<long long> p2(n);
p2[0] = 1;
for (int i = 0; i < n - 1; ++i) p2[i + 1] = p2[i] * 2LL % mod;
long long ans = 0;
for (int i = 0; i < n; ++i) ans = (ans + (cnt[i] != n - 1 ? p2[cnt[i]] : p2[cnt[i]] - 2)) % mod;
cout << ans << endl;
}
テナガザル