QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#458159 | #7408. Determination | HuTao | WA | 3ms | 18004kb | C++14 | 1.5kb | 2024-06-29 16:05:38 | 2024-06-29 16:05:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 5, P = 1e9 + 7;
int n;
LL v, x[N], y[N], z[N];
int fa[N], la[N], ne[N], en[N], idx;
LL f[N][3][4], g[3][4];
void Add(int a, int b)
{
ne[ ++ idx] = la[a];
la[a] = idx;
en[idx] = b;
}
void DP(int u)
{
memset(f[u], 0, sizeof f[u]);
f[u][0][3] = 1;
f[u][1][2] = 1;
f[u][1][1] = 1;
f[u][2][0] = 1;
f[u][0][0] = x[u];
for(int i = la[u]; i; i = ne[i])
{
int v = en[i];
memset(g, 0, sizeof g);
for(int i = 0; i < 3; i ++ )
for(int j = 0; j <= i; j ++ )
for(int k = 0; k < 4; k ++ )
for(int l = 0; l <= k; l ++ )
if((l & k) == l)
{
LL s = f[u][i - j][k] * f[v][j][l];
if(l & 1) s = s % P * y[v];
if(l & 2) s = s % P * z[v];
g[i][k ^ l] = (g[i][k ^ l] + s) % P;
}
memcpy(f[u], g, sizeof g);
}
swap(f[u][0][1], f[u][0][2]);
swap(f[u][1][1], f[u][1][2]);
swap(f[u][2][1], f[u][2][2]);
f[u][0][0] = P - f[u][0][0];
f[u][1][0] = P - f[u][1][0];
f[u][2][0] = P - f[u][2][0];
}
int main()
{
scanf("%d%lld", &n, &v);
for(int i = 1; i <= n; i ++ ) la[i] = 0;
idx = 0;
for(int i = 1; i <= n; i ++ )
{
scanf("%lld", &x[i]);
x[i] = (x[i] - v + P) % P;
}
for(int i = 2; i <= n; i ++ )
{
scanf("%d%lld%lld", &fa[i], &y[i], &z[i]);
Add(fa[i], i);
y[i] = (y[i] - v + P) % P;
z[i] = (z[i] - v + P) % P;
}
for(int i = n; i >= 1; i -- ) DP(i);
LL ans = (f[1][0][0] + f[1][2][0] * v) % P;
if(n & 1) ans = (P - ans) % P;
printf("%lld\n", ans);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 18004kb
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:
16285968
result:
wrong answer 1st numbers differ - expected: '233', found: '16285968'