Submission #76084440


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
int n,f[200005];
ll ans=1,a[200005],b[200005],c[200005],fac[10000007];
vector<int> e[200005];
int dfs(int u){
	int ans=a[u];
	for(int i=0;i<e[u].size();i++) ans+=dfs(e[u][i]);
	c[u]=ans;
	return ans-b[u];
}
ll fact(ll x){
	if(x<=10000000) return fac[x];
	ll ans=fac[10000000];
	for(int i=10000001;i<=x;i++) (ans*=i)%=mod;
	return ans;
}
ll qpow(ll a,ll k,ll mod){
	ll ans=1;
	while(k){
		if(k&1) (ans*=a)%=mod;
		(a*=a)%=mod,k>>=1;
	}
	return ans;
}
ll inv(ll x){return qpow(x,mod-2,mod);}
ll C(ll n,ll m){return fact(n)*inv(fact(m)*fact(n-m)%mod)%mod;}
int main(){
	cin>>n,fac[0]=1;
	for(int i=1;i<=10000000;i++) fac[i]=fac[i-1]*i%mod;
	for(int i=2;i<=n;i++) cin>>f[i],e[f[i]].push_back(i);
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	dfs(1);
	for(int i=1;i<=n;i++) if(c[i]<b[i]){cout<<0;return 0;}
	for(int i=1;i<=n;i++) (ans*=C(c[i],b[i]))%=mod;
	cout<<ans;
}

Submission Info

Submission Time
Task E - Select from Subtrees
User Rya_
Language C++23 (GCC 15.2.0)
Score 0
Code Size 1016 Byte
Status WA
Exec Time > 2000 ms
Memory 107416 KiB

Compile Error

./Main.cpp: In function 'int dfs(int)':
./Main.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |         for(int i=0;i<e[u].size();i++) ans+=dfs(e[u][i]);
      |                     ~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
AC × 2
TLE × 1
AC × 10
WA × 21
TLE × 4
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 70 ms 81512 KiB
example_01.txt AC 59 ms 81444 KiB
example_02.txt TLE > 2000 ms 81404 KiB
hand_00.txt WA 198 ms 107232 KiB
hand_01.txt WA 136 ms 87696 KiB
hand_02.txt WA 168 ms 94696 KiB
hand_03.txt WA 177 ms 99660 KiB
hand_04.txt WA 169 ms 99536 KiB
hand_05.txt WA 169 ms 99708 KiB
hand_06.txt WA 179 ms 102604 KiB
hand_07.txt TLE > 2000 ms 81368 KiB
hand_08.txt TLE > 2000 ms 81384 KiB
hand_09.txt WA 195 ms 107308 KiB
hand_10.txt TLE > 2000 ms 81476 KiB
hand_11.txt AC 184 ms 107416 KiB
random_00.txt AC 61 ms 81528 KiB
random_01.txt WA 60 ms 81568 KiB
random_02.txt WA 59 ms 81564 KiB
random_03.txt AC 59 ms 81504 KiB
random_04.txt AC 58 ms 81640 KiB
random_05.txt WA 145 ms 91800 KiB
random_06.txt WA 123 ms 89960 KiB
random_07.txt AC 72 ms 83232 KiB
random_08.txt AC 142 ms 91316 KiB
random_09.txt WA 127 ms 90556 KiB
random_10.txt WA 171 ms 94872 KiB
random_11.txt WA 173 ms 94872 KiB
random_12.txt WA 163 ms 95052 KiB
random_13.txt AC 172 ms 94916 KiB
random_14.txt WA 172 ms 94916 KiB
random_15.txt AC 171 ms 94916 KiB
random_16.txt WA 172 ms 95052 KiB
random_17.txt WA 171 ms 94808 KiB
random_18.txt WA 171 ms 94852 KiB
random_19.txt WA 171 ms 94840 KiB