結果
| 問題 | No.3412 Christmas Tree Coloring |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-21 22:16:06 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 579 bytes |
| 記録 | |
| コンパイル時間 | 2,033 ms |
| コンパイル使用メモリ | 194,700 KB |
| 実行使用メモリ | 23,112 KB |
| 最終ジャッジ日時 | 2025-12-21 22:16:11 |
| 合計ジャッジ時間 | 4,734 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000010, MOD = 998244353, INF = 0x3f3f3f3f;
int n, m, w[N];
ll res, p[N];
int sz[N];
int main() {
p[0] = 1;
for (int i = 1; i < N; i++) p[i] = (p[i - 1] << 1) % MOD;
scanf("%d", &n);
for (int i = 1, a, b; i < n; i++) {
scanf("%d%d", &a, &b);
sz[a]++, sz[b]++;
}
for (int i = 1; i < n + 1; i++) {
res -= (sz[i] == n - 1) << 1;
res = (res + p[sz[i]] + MOD) % MOD;
}
printf("%lld\n", res);
return 0;
}