import ru.ifmo.testlib.Checker;
import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;
import ru.ifmo.testlib.Outcome.Type;

import java.util.ArrayList;
import java.util.List;

public class Check implements Checker {

    public static final Outcome OK_NO_ANSWER = new Outcome(Type.OK, "no answer");
    public static final Outcome OK_CORRECT = new Outcome(Type.OK, "correct");

    public static final Outcome WA_NO_ANSWER = new Outcome(Type.WA, "jury didn't found answer, but participant found");
    public static final Outcome WA_NOT_FOUND = new Outcome(Type.WA, "jury found answer, but participant didn't");
    public static final Outcome WA_INCORRECT = new Outcome(Type.WA, "participant answer is incorrect");

    public static final Outcome PE_NOT_ENOUGH_NUMBERS = new Outcome(Type.PE, "participant's output should contain exactly N numbers");
    public static final Outcome PE_BAD_NUMBER = new Outcome(Type.PE, "all values should be from [1, 10^9]");
    public static final Outcome PE_NOT_NUMBER = new Outcome(Type.PE, "participant's output should contain only numbers");

    public static final int MAX = (int) 1e9;
    public static final int MIN = 1;

    @Override
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int n = inf.nextInt();
        int t = inf.nextInt();

        verts = new Node[n];
        for (int i = 0; i < n; i++) {
            verts[i] = new Node();
        }

        for (int i = 0; i < n; i++) {
            int l = inf.nextInt();
            int r = inf.nextInt();
            verts[i].value = inf.nextInt();

            verts[i].left = l - 1;
            verts[i].right = r - 1;
        }

        boolean hasAns = ans.nextInt() != -1;

        q = new ArrayList<>();
        dfs(0, t);

        List<String> oufTokens = new ArrayList<>();
        while (!ouf.seekEoF()) {
            oufTokens.add(ouf.nextToken());
        }

        try {
            if (hasAns) {
                if (oufTokens.size() == 1 && Integer.parseInt(oufTokens.get(0)) == -1) {
                    return WA_NOT_FOUND;
                }
                if (oufTokens.size() != n) {
                    return PE_NOT_ENOUGH_NUMBERS;
                }

                for (int i = 0; i < n; i++) {
                    int x = verts[i].newValue = Integer.parseInt(oufTokens.get(i));
                    if (x < MIN || x > MAX) {
                        throw PE_BAD_NUMBER;
                    }
                }
                int last = 0;
                for (int x : q) {
                    if (x <= 0) {
                        x = verts[-x].newValue;
                    }

                    if (x <= last) {
                        return WA_INCORRECT;
                    }
                    last = x;
                }
            } else {
                if (oufTokens.size() != 1) return WA_NO_ANSWER;
                if (Integer.parseInt(oufTokens.get(0)) == -1) {
                    return OK_NO_ANSWER;
                } else {
                    return WA_NO_ANSWER;
                }
            }
        } catch (NumberFormatException e) {
            return PE_NOT_NUMBER;
        }

        return OK_CORRECT;
    }

    Node[] verts;

    List<Integer> q;

    void dfs(int v, int val) {
        if (v != -1) dfs(verts[v].left, verts[v].value);
        q.add(val);
        if (v != -1) dfs(verts[v].right, -v);
    }

    final class Node {
        int value;
        int newValue;
        int left, right;

        public Node() {
        }
    }
}
