import static java.lang.Math.min;
import static java.util.Arrays.fill;

import java.util.*;

import ru.ifmo.testlib.*;
import ru.ifmo.testlib.Outcome.Type;

public class Check implements Checker {

    static class Edge {
        int a, b, cost;

        Edge(int a, int b, int cost) {
            this.a = a;
            this.b = b;
            this.cost = cost;
        }
    }

    int[] p, r;
    int get(int x) {
        if (p[x] == x) {
            return p[x];
        }
        return p[x] = get(p[x]);
    }

    boolean union(int a, int b) {
        a = get(a);
        b = get(b);
        if (a == b) {
            return false;
        }
        if (r[a] > r[b]) {
            p[b] = a;
        } else if (r[a] < r[b]) {
            p[a] = b;
        } else {
            p[a] = b;
            r[b]++;
        }
        return true;
    }
    @Override
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int n = inf.nextInt();
        int m = inf.nextInt();
        int k = inf.nextInt();
        Edge[] edges = new Edge[m];
        for (int i = 0; i < m; i++) {
            edges[i] = new Edge(inf.nextInt() - 1, inf.nextInt() - 1, inf.nextInt());
        }
        boolean answerExists = ans.nextInt() != -1;
        int[] answer = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            int x = ouf.nextInt();
            if (x == -1) {
                if (i == 0 && !answerExists) {
                    return new Outcome(Type.OK, "No solution");
                } else {
                    return new Outcome(Type.WA, "Unexpected -1");
                }
            }
            if (x < 1 || x > m) {
                return new Outcome(Type.WA, "Invalid edge: " + x);
            }
            answer[i] = x - 1;
        }
        int outK = 0;
        p = new int[n];
        r = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = i;
        }
        for (int i = 0; i < answer.length; i++) {
            Edge e = edges[answer[i]];
            if (!union(e.a, e.b)) {
                return new Outcome(Type.WA, "Wrong edge: " + (answer[i] + 1));
            }
            outK += e.cost;
        }
        if (outK != k) {
            return new Outcome(Type.WA, "Wrong k: " + outK + " != " + k);
        }
        if (!answerExists) {
            return new Outcome(Type.FAIL, "Participant found solution!");
        }
        return new Outcome(Type.OK, "Ok, k = " + k);
    }
}
