#include #include using namespace std; typedef struct node { long long int value; int leftInd, rightInd; int incoming; int v2, rp; char letter; bool visited; void toggle() { if (letter == 'R') letter = 'L'; else letter = 'R'; } } nodetype; nodetype node[500005]; int main() { priority_queue sortednodes; long long int n; int m, i; scanf (" %lld %d", &n, &m); for (i = 1; i <= m; i++) { scanf (" %c %d %d", &node[i].letter, &node[i].leftInd, &node[i].rightInd); node[node[i].leftInd].incoming++; node[node[i].rightInd].incoming++; node[i].value = 0; } for (i = 1; i <= m; i++) if (node[i].incoming == 0) sortednodes.push(i); node[1].value = n; while (!sortednodes.empty() && sortednodes.top() != 0) { int at = sortednodes.top(); sortednodes.pop(); //printf("DB -- %d: v %lld\n", at, node[at].value); long long int leftv, rightv; leftv = rightv = node[at].value/2; if (node[at].value%2 != 0) { //printf("Hallo %c ", node[at].letter); if (node[at].letter == 'L') leftv++; else if (node[at].letter == 'R') rightv++; node[at].toggle(); //printf("%c\n", node[at].letter); } node[node[at].leftInd ].value += leftv; node[node[at].rightInd].value += rightv; node[node[at].leftInd ].incoming--; node[node[at].rightInd].incoming--; if (node[node[at].leftInd ].incoming == 0) sortednodes.push(node[at].leftInd); if (node[node[at].rightInd].incoming == 0 && node[at].rightInd != node[at].leftInd) sortednodes.push(node[at].rightInd); } for (i = 1; i <= m; i++) printf ("%c", node[i].letter); printf("\n"); return 0; }