#include <stdio.h>
#define MAX 1000000
int dp[MAX];
int P[MAX], C[MAX], K[MAX], child[MAX][1000], index[MAX];
int mod = 1000000007;
void dfs(int i) {
int j = 1;
while (j <= index[i]) {
dfs(child[i][j]);
if ((C[child[i][j]] == C[i]) && (K[i] - K[child[i][j]] == 1))
dp[i] = (dp[i] % mod + dp[child[i][j]] % mod) % mod;
++j;
}
}
int main() {
int T, N, X, i, j;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &N, &X);
for (i = 0; i < N; ++i)
index[i] = 0;
for (i = 1; i < N; ++i) {
scanf("%d", &P[i]);
child[P[i]][++index[P[i]]] = i;
}
for (i = 0; i < N; ++i)
scanf("%d", &C[i]);
for (i = 0; i < N; ++i) {
scanf("%d", &K[i]);
if (K[i])
dp[i] = 0;
else
dp[i] = 1;
}
dfs(0);
for (i = 0; i < N; ++i)
printf("%d\n", dp[i]);
}
return 0;
}
当我编译上面的代码中,我得到了以下错误:定位误差
In function `dfs':
(.text+0xa): relocation truncated to fit: R_X86_64_32S against symbol `index' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x3b): relocation truncated to fit: R_X86_64_32S against symbol `index' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x4f): relocation truncated to fit: R_X86_64_32S against symbol `C' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x56): relocation truncated to fit: R_X86_64_32S against symbol `C' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x60): relocation truncated to fit: R_X86_64_32S against symbol `K' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x67): relocation truncated to fit: R_X86_64_32S against symbol `K' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x74): relocation truncated to fit: R_X86_64_32S against symbol `dp' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x84): relocation truncated to fit: R_X86_64_32S against symbol `dp' defined in COMMON section in /tmp/cc0VMXET.o
(.text+0x97): relocation truncated to fit: R_X86_64_32S against symbol `dp' defined in COMMON section in /tmp/cc0VMXET.o
In function `main':
(.text.startup+0x6e): relocation truncated to fit: R_X86_64_32S against symbol `index' defined in COMMON section in /tmp/cc0VMXET.o
(.text.startup+0xba): additional relocation overflows omitted from the output
error: ld returned 1 exit status
我知道这是什么错误,它是如何发生的。我已经在stackoverflow中搜索它,但我不明白如何纠正它。有人可以告诉我如何纠正我的代码?
你怎么编?什么是论据?并在什么平台上?什么编译器? – bolov
我认为你已经违反了int变量的容量,mod' –
@ Md.RezwanulHaque大概这个问题的答案是“没有警告”,像往常一样。 –