Submission #45791900


Source Code Expand

// LUOGU_RID: 125557934
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 2e5 + 10, MOD = 998244353;
int n;
vector <int> v[N];
int dep[N], ans, inv[N], s[N];
inline void binom(int x) {
	inv[1] = 1;
	F(i, 2, x) inv[i] = (ll) (MOD - MOD / i) * inv[MOD % i] % MOD;
	F(i, 1, x) s[i] = (s[i - 1] + inv[i]) % MOD;
}
inline void add(int &x, ll y) { x = (x + y) % MOD; }
void dfs(int x, int fa) {
	dep[x] = dep[fa] + 1;
	add(ans, s[dep[x]]);
	for (int i: v[x])
		if (i != fa) dfs(i, x);
}
signed main() {
	read(n);
	binom(n);
	F(i, 2, n) {
		int x; read(x);
		v[x].push_back(i);
	}
	dfs(1, 0);
	cout << ans;
	return 0;
}

Submission Info

Submission Time
Task D - Removing Gacha
User ast123
Language C++ 20 (gcc 12.2)
Score 700
Code Size 1302 Byte
Status AC
Exec Time 22 ms
Memory 26340 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 32
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt
All 00-sample-001.txt, 00-sample-002.txt, 01-random-001.txt, 01-random-002.txt, 01-random-003.txt, 01-random-004.txt, 01-random-005.txt, 01-random-006.txt, 01-random-007.txt, 01-random-008.txt, 01-random-009.txt, 01-random-010.txt, 01-random-011.txt, 01-random-012.txt, 01-random-013.txt, 01-random-014.txt, 01-random-015.txt, 02-max-001.txt, 02-max-002.txt, 02-max-003.txt, 02-max-004.txt, 02-max-005.txt, 02-max-006.txt, 02-max-007.txt, 02-max-008.txt, 02-max-009.txt, 02-max-010.txt, 03-test-001.txt, 03-test-002.txt, 03-test-003.txt, 03-test-004.txt, 03-test-005.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 2 ms 3548 KiB
00-sample-002.txt AC 2 ms 3528 KiB
01-random-001.txt AC 21 ms 15364 KiB
01-random-002.txt AC 18 ms 14272 KiB
01-random-003.txt AC 18 ms 13692 KiB
01-random-004.txt AC 17 ms 13276 KiB
01-random-005.txt AC 21 ms 15812 KiB
01-random-006.txt AC 11 ms 10392 KiB
01-random-007.txt AC 16 ms 13728 KiB
01-random-008.txt AC 12 ms 11484 KiB
01-random-009.txt AC 15 ms 13168 KiB
01-random-010.txt AC 13 ms 12232 KiB
01-random-011.txt AC 22 ms 13148 KiB
01-random-012.txt AC 16 ms 10352 KiB
01-random-013.txt AC 19 ms 11792 KiB
01-random-014.txt AC 17 ms 10892 KiB
01-random-015.txt AC 15 ms 9896 KiB
02-max-001.txt AC 22 ms 16144 KiB
02-max-002.txt AC 22 ms 16168 KiB
02-max-003.txt AC 22 ms 16120 KiB
02-max-004.txt AC 22 ms 16216 KiB
02-max-005.txt AC 22 ms 16128 KiB
02-max-006.txt AC 17 ms 14648 KiB
02-max-007.txt AC 17 ms 14644 KiB
02-max-008.txt AC 17 ms 14564 KiB
02-max-009.txt AC 17 ms 14600 KiB
02-max-010.txt AC 17 ms 14816 KiB
03-test-001.txt AC 7 ms 6556 KiB
03-test-002.txt AC 6 ms 6492 KiB
03-test-003.txt AC 21 ms 26204 KiB
03-test-004.txt AC 21 ms 26340 KiB
03-test-005.txt AC 2 ms 3568 KiB