QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#463403 | #7408. Determination | wangyu0915 | WA | 31ms | 13924kb | C++14 | 2.3kb | 2024-07-04 20:02:22 | 2024-07-04 20:02:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace IO{
template<typename T> inline void write(T x){
if(x<0) putchar('-'),x=-x;
if(x==0){
putchar('0'); return ;
}
if(x>9) write(x/10);
putchar(x%10+'0');
return ;
}
template<typename T> inline void read(T &x){
x=0; int w=1; char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') w=-1; ch=getchar();
}
while(isdigit(ch))
x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x*=w; return ;
}
}
using namespace IO;
#define writesp(x) write(x),putchar(' ')
#define writeln(x) write(x),putchar('\n')
#define inf 0x3f3f3f3f
#define mod 1000000007
#define N 1000010
#define pb emplace_back
#define int long long
#define szi sizeof(int)
#define il inline
int T,n,s,x,y,d[N],a[N],b[N],hd[N],tot=0,dp[N][6];
// 0/1: 子树内环闭合,且不存在额外边,rt不在/在环中
// 2/3: 子树内环闭合,存在额外边,rt不在/在环中
// 4/5: 子树内环未闭合,存在出/入这个子树的额外边(此时存在额外边的环一定包含 rt)
struct node{int v,nxt;}eg[N];
il void madd(int &x,int y){
x=(x+y>=mod)?(x+y-mod):(x+y); return ;
}
il void add(int x,int y){
eg[++tot].v=y,eg[tot].nxt=hd[x],hd[x]=tot;
return ;
}
il void dfs(int x){
int t[6]; dp[x][0]=dp[x][4]=dp[x][5]=1;
dp[x][1]=mod-d[x],dp[x][3]=mod-s,dp[x][2]=0;
for(int i=hd[x];i;i=eg[i].nxt){
int y=eg[i].v; dfs(y),memcpy(t,dp[x],sizeof(t));
dp[x][0]=t[0]*dp[y][1]%mod;
dp[x][1]=(t[1]*dp[y][1]+mod-t[0]*dp[y][0]%mod*a[y]%mod*b[y]%mod)%mod;
dp[x][2]=(t[0]*dp[y][3]+t[2]*dp[y][1])%mod;
dp[x][3]=(t[1]*dp[y][3]+t[3]*dp[y][1])%mod;
dp[x][3]=(dp[x][3]+mod-(t[0]*dp[y][2]+t[2]*dp[y][0])%mod*a[y]%mod*b[y]%mod)%mod;
dp[x][3]=(dp[x][3]+mod-(t[4]*dp[y][5]%mod*b[y]+t[5]*dp[y][4]%mod*a[y])%mod*s%mod)%mod;
dp[x][4]=(t[0]*dp[y][4]%mod*a[y]+t[4]*dp[y][1])%mod;
dp[x][5]=(t[0]*dp[y][5]%mod*b[y]+t[5]*dp[y][1])%mod;
}
return ;
}
il void solve(){
read(n),read(s); memset(hd,0,szi*(n+1)),tot=0;
for(int i=1;i<=n;++i) read(d[i]),madd(d[i],mod-s);
for(int i=2;i<=n;++i){
read(x),add(x,i);
read(a[i]),read(b[i]),madd(a[i],mod-s),madd(b[i],mod-s);
}
dfs(1),writeln((mod-dp[1][1]+mod-dp[1][3])%mod);
return ;
}
signed main(){
// freopen("det.in","r",stdin);
// freopen("det.out","w",stdout);
read(T); while(T--) solve();
// solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 13884kb
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: 31ms
memory: 13924kb
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:
106269585 483416679 657792092 79126948 524089509 891399859 721905386 306275851 0 656093789 884245911 47931137 995236682 508180962 537867394 416802299 172001791 924935082 198496486 425744594 1 860065349 654344063 1 924917560 893397792 180825552 537904471 165248658 0 844642178 959870186 931007058 9250...
result:
wrong answer 1st numbers differ - expected: '893730422', found: '106269585'