#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;
}
Quand je compilé le code ci-dessus, je me suis l'erreur suivante:Relocation erreur
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
Je sais ce que cette erreur est, comment se produit-il. Je l'ai cherché dans stackoverflow, mais je ne peux pas comprendre comment le corriger. Quelqu'un peut-il me dire comment corriger mon code?
comment compilez-vous? Quels sont les arguments? Et sur quelle plateforme? Quel compilateur? – bolov
Je pense que vous avez violé la capacité d'un int avec la variable 'mod' –
@ Md.RezwanulHaque Vraisemblablement la réponse à cette question est" sans avertissements ", comme d'habitude. –