結果

問題 No.2214 Products on Tree
ユーザー kwm_tkwm_t
提出日時 2023-02-11 17:58:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 3,000 ms
コード長 1,627 bytes
コンパイル時間 4,584 ms
コンパイル使用メモリ 266,548 KB
実行使用メモリ 32,876 KB
最終ジャッジ日時 2023-09-22 14:10:31
合計ジャッジ時間 8,626 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 125 ms
13,548 KB
testcase_04 AC 128 ms
13,928 KB
testcase_05 AC 122 ms
13,272 KB
testcase_06 AC 72 ms
10,260 KB
testcase_07 AC 20 ms
5,164 KB
testcase_08 AC 12 ms
4,452 KB
testcase_09 AC 24 ms
5,592 KB
testcase_10 AC 68 ms
10,088 KB
testcase_11 AC 34 ms
6,652 KB
testcase_12 AC 43 ms
7,352 KB
testcase_13 AC 134 ms
14,164 KB
testcase_14 AC 134 ms
14,088 KB
testcase_15 AC 131 ms
14,320 KB
testcase_16 AC 124 ms
14,104 KB
testcase_17 AC 119 ms
14,080 KB
testcase_18 AC 47 ms
11,912 KB
testcase_19 AC 54 ms
12,428 KB
testcase_20 AC 44 ms
11,396 KB
testcase_21 AC 33 ms
9,868 KB
testcase_22 AC 69 ms
15,144 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 66 ms
25,048 KB
testcase_29 AC 15 ms
6,348 KB
testcase_30 AC 54 ms
17,804 KB
testcase_31 AC 81 ms
17,996 KB
testcase_32 AC 67 ms
16,576 KB
testcase_33 AC 90 ms
32,876 KB
testcase_34 AC 91 ms
32,716 KB
testcase_35 AC 113 ms
23,608 KB
testcase_36 AC 110 ms
23,568 KB
testcase_37 AC 73 ms
13,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<mint,mint>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
vector<vector<int>>to;
P dfs(int v, int d = 0, int p = -1) {
	if ((-1 != p) && (1 == to[v].size()))return { 1,1 };
	vector<P>vec;
	for (int e : to[v]) {
		if (p == e) continue;
		auto get = dfs(e, d + 1, v);
		vec.push_back(get);
	}
	int sz = vec.size();
	vector<mint>l(sz + 1), r(sz + 1);
	l[0] = 1, r[sz] = 1;
	rep(i, sz)l[i + 1] = l[i] * (vec[i].first + vec[i].second);
	rrep(i, sz)r[i] = r[i + 1] * (vec[i].first + vec[i].second);
	P ret = { l[sz],l[sz] };
	rep(i, sz) ret.first += l[i] * r[i + 1] * vec[i].first;
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	to.resize(n);
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--, b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	auto ans = dfs(0);
	cout << ans.first.val() << endl;
	return 0;
}
0