#include <stdio.h>
#define MAX_NODES 1001
int numOfNodes;
int resultOfLeaf[MAX_NODES];
typedef struct Edge{
int to;
int next;
}Edge;
Edge EdgeArray[MAX_NODES];
int EdgeNum;
int head[MAX_NODES];
int move(int node, int competitor){
if (resultOfLeaf[node] != -2)
return resultOfLeaf[node];
int draw = 0;
int i;
for (i = head[node]; i != 0; i = EdgeArray[i].next){
int result = move(EdgeArray[i].to, -competitor);
if (result == competitor)
return result;
if (result == 0)
draw = 1;
}
return draw ? 0 : -competitor;
}
int main(){
scanf("%d", &numOfNodes);
int to, from;
char symbol[2];
resultOfLeaf[1] = -2;
for (to = 2; to <= numOfNodes; to++){
resultOfLeaf[to] = -2;
scanf("%s%d", symbol, &from);
EdgeNum++;
EdgeArray[EdgeNum].to = to;
EdgeArray[EdgeNum].next = head[from];
head[from] = EdgeNum;
if (symbol[0] == 'L')
scanf("%d", &resultOfLeaf[to]);
}
int result = move(1, 1);
if (result == 1)
printf("+1\n");
else if (result == -1)
printf("-1\n");
else
printf("0\n");
return 0;
}
URAL 1282 Game Tree
最新推荐文章于 2021-08-04 15:15:41 发布