2799 | 2023-01-25 20:50:49 | itakacs | XORfa visszatér | cpp11 | Forditási hiba |
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#define MAX_Q 50000
struct Node {
unsigned short parent;
unsigned weight_to_parent;
};
unsigned short backtrack(unsigned short start_node, const struct Node* tree, unsigned short* bt) {
unsigned short i, depth;
struct Node current_node;
bt[0] = 1;
if(start_node == 1)
{
bt[1] = 0U;
return 0U;
}
current_node = tree[start_node];
for(depth = 1U; current_node.parent != 1; depth++)
current_node = tree[current_node.parent];
bt[depth] = start_node;
bt[depth + 1] = 0U;
current_node = tree[start_node];
for(i = depth - 1; i > 0; i--)
{
bt[i] = current_node.parent;
current_node = tree[current_node.parent];
}
return depth;
}
int main()
{
static bool I[MAX_Q + 1];
unsigned xor, mxor;
unsigned short i, j, k, l, m, d0, d1, N, Q, *bts[2];
struct Node node;
scanf("%hu %hu", &N, &Q);
for(i = 0U; i < 2; i++)
bts[i] = malloc((N + 1) * sizeof(short));
struct Node* tree = malloc((N + 1) * sizeof(struct Node));
for(i = 1U; i < N; i++)
{
scanf("%hu %hu %u", &node.parent, &j, &node.weight_to_parent);
tree[j] = node;
}
for(i = 0U; i < Q; i++)
{
scanf("%hu", &j);
I[j] = !I[j];
//printf("next round\n");
mxor = 0U;
for(j = 1U; j <= Q; j++)
{
if(!I[j])
continue;
d0 = backtrack(j, tree, bts[0]);
for(k = j + 1; k <= Q; k++)
{
if(!I[k])
continue;
d1 = backtrack(k, tree, bts[1]);
for(l = 0U; bts[0][l] == bts[1][l]; l++);
l--;
//printf("common vertex is %hu\n", bts[0][l]);
xor = 0U;
//printf("first, xor is %u\n", xor);
while(bts[0][d0] != bts[0][l])
{
//printf("ok, now take weight of %hu\n", bts[0][d0]);
xor ^= tree[bts[0][d0--]].weight_to_parent;
//printf("after this operation, xor is %u\n", xor);
}
//printf("going down\n");
while(bts[1][++l] != 0)
{
//printf("ok, now take weight of %hu\n", bts[1][l]);
xor ^= tree[bts[1][l]].weight_to_parent;
//printf("after this operation, xor is %u\n", xor);
}
if(xor > mxor)
mxor = xor;
//printf("%hu %hu %u\n", j, k, xor);
}
}
printf("%u\n", mxor);
}
return 0;
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:46:14: error: expected unqualified-id before 'xor' token
46 | unsigned xor, mxor;
| ^~~
main.cpp:53:24: error: invalid conversion from 'void*' to 'short unsigned int*' [-fpermissive]
53 | bts[i] = malloc((N + 1) * sizeof(short));
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
| |
| void*
main.cpp:55:31: error: invalid conversion from 'void*' to 'Node*' [-fpermissive]
55 | struct Node* tree = malloc((N + 1) * sizeof(struct Node));
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| void*
main.cpp:69:9: error: 'mxor' was not declared in this scope
69 | mxor = 0U;
| ^~~~
main.cpp:90:17: error: expected primary-expression before 'xor' token
90 | xor = 0U;
| ^~~
main.cpp:90:21: error: expected primar...