QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460787#7408. DeterminationhxhhxhWA 66ms36568kbC++141.5kb2024-07-02 09:43:262024-07-02 09:43:30

Judging History

你现在查看的是最新测评结果

  • [2024-07-02 09:43:30]
  • 评测
  • 测评结果:WA
  • 用时:66ms
  • 内存:36568kb
  • [2024-07-02 09:43:26]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int n,v,d[1000006],p[1000006],a[1000006],b[1000006],dp[1000006][4][2],f[2][5][2];
vector<int>e[1000006];
void dfs(int x){
	memset(dp[x],0,sizeof(dp[x]));
	for(int i:e[x]) dfs(i);
	memset(f,0,sizeof(f));
	int t=0;
	f[0][0][0]=1; 
	for(int i:e[x]){
		memset(f[t^1],0,sizeof(f[t]));
		for(int j=0;j<2;j++){
			for(int k=0;k+j<2;k++){
				f[t^1][0][j+k]+=f[t][0][j]*dp[i][0][k];
				for(int l=1;l<4;l++) f[t^1][l][j+k]+=f[t][l][j]*dp[i][0][k]+f[t][0][j]*dp[i][l][k];
				f[t^1][4][j+k]+=f[t][2][j]*dp[i][3][k]+f[t][3][j]*dp[i][2][k]+f[t][4][j]*dp[i][0][k];
			}
		}
		t^=1;
		for(int j=0;j<2;j++) for(int k=0;k<4;k++) f[t][k][j]%=mod;
	}
	for(int i=0;i<2;i++){
		dp[x][0][i]-=f[t][0][i]*d[x]+f[t][1][i];
		dp[x][1][i]+=f[t][0][i]*a[x]%mod*b[x];
		dp[x][2][i]+=(f[t][0][i]+f[t][2][i])*a[x];
		dp[x][3][i]+=(f[t][0][i]+f[t][3][i])*b[x];
	}
	dp[x][0][1]-=f[t][0][0]+f[t][2][0]+f[t][3][0]+f[t][4][0];
	for(int i=0;i<2;i++) for(int j=0;j<4;j++) dp[x][j][i]%=mod;
}
void doing(){
	scanf("%lld %lld",&n,&v);
	for(int i=1;i<=n;i++) scanf("%lld",&d[i]),d[i]-=v;
	for(int i=2;i<=n;i++) scanf("%lld %lld %lld",&p[i],&a[i],&b[i]),a[i]-=v,b[i]-=v;
	for(int i=1;i<=n;i++) e[i].clear();
	for(int i=2;i<=n;i++) e[p[i]].push_back(i);
	dfs(1);
	int ans=(dp[1][0][1]*v%mod+dp[1][0][0]+mod*2)%mod;
	if(n&1) ans=(mod-ans)%mod;
	printf("%lld\n",ans);
}
signed main(){
	int T; 
	cin>>T;
	while(T--) doing();
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 32332kb

input:

3
1 23333
233
3 1
1 1 1
1 2 3
1 4 5
3 1
2 3 4
1 4 5
2 6 7

output:

233
1000000003
999999923

result:

ok 3 number(s): "233 1000000003 999999923"

Test #2:

score: -100
Wrong Answer
time: 66ms
memory: 36568kb

input:

50000
8 322029253
0 4 1 8 2 4 2 6
1 944501012 390210770
2 901049174 103930626
3 865552309 989846658
4 894181655 586868306
2 819783208 393532481
6 617853941 785991126
2 81883211 919505569
7 896017220
5 2 2 5 7 3 5
1 747310272 809584267
1 964602148 156726243
3 521346132 229656100
4 339712528 807083254...

output:

95747073
73746476
936604294
920873059
524089509
108600148
721905386
693724156
0
656093789
708229849
952068870
211088384
491819045
124785782
322039132
172001791
75064925
801503521
574255413
1
27820213
861775578
1
924917560
508760975
180825552
794342988
520100656
0
155357829
959870186
931007058
749755...

result:

wrong answer 1st numbers differ - expected: '893730422', found: '95747073'