Language: Java

import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = 1 << 61;

    static int n,m,r;
    static int[] R;
    static long[][] dist;
    static long ans = inf;
    static boolean[] visited;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        r = in.nextInt();
        R = new int[r];
        for(int i = 0; i < r; i++) R[i] = in.nextInt()-1;

        visited = new boolean[r];
        Arrays.fill(visited, false);

        dist = new long[n][n];
        for(int i = 0; i < n; i++) {
            Arrays.fill(dist[i], inf);
            dist[i][i] = 0;
        }
        for(int i = 0; i < m; i++) {
            int a = in.nextInt()-1;
            int b = in.nextInt()-1;
            int c = in.nextInt();
            dist[a][b] = c;
            dist[b][a] = c;
        }

        for(int k = 0; k < n; k++) {
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < n; j++) {
                    dist[i][j] = Math.min(dist[i][k] + dist[k][j], dist[i][j]);
                }
            }
        }

        for(int i = 0; i < r; i++) {
            dfsWithStack(R[i]);
        }
        print(ans);
    }

    static void dfs(int cnt, int last, long d) {
        if(cnt == r+1) {
            ans = Math.min(ans, d);
            return;
        }

        for(int i = 0; i < r; i++) {
            if(!visited[i]) {
                visited[i] = true;
                if(last == -1) dfs(cnt+1, i, 0);
                else           dfs(cnt+1, i, d + dist[R[last]][R[i]]);
                visited[i] = false;
            }
        }
    }

    static void dfsWithStack(int startAt) {
        Stack<Tuple3> stack = new Stack<>();
        Tuple3 t = new Tuple3(startAt, 1, 0);
        stack.push(t);
        boolean[] used = new boolean[9];

        while(!stack.isEmpty()) {
            Tuple3 current = stack.pop();
            if(current.y == r) {
                ans = Math.min(ans, current.z);
                return;
            }

            used[current.x] = true;
            for(int i = 0; i < r; i++) {
                if(!used[R[i]]) {
                    Tuple3 next = new Tuple3( R[i], current.y + 1, current.z + dist[current.x][R[i]] );
                    stack.push(next);
                }
            }
        }
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }

    static void print(long i) {
        System.out.println(i);
    }
}

Compiler output:
Main.java:68: error: cannot find symbol
        Stack<Tuple3> stack = new Stack<>();
              ^
  symbol:   class Tuple3
  location: class Main
Main.java:69: error: cannot find symbol
        Tuple3 t = new Tuple3(startAt, 1, 0);
        ^
  symbol:   class Tuple3
  location: class Main
Main.java:69: error: cannot find symbol
        Tuple3 t = new Tuple3(startAt, 1, 0);
                       ^
  symbol:   class Tuple3
  location: class Main
Main.java:74: error: cannot find symbol
            Tuple3 current = stack.pop();
            ^
  symbol:   class Tuple3
  location: class Main
Main.java:83: error: cannot find symbol
                    Tuple3 next = new Tuple3( R[i], current.y + 1, current.z + dist[current.x][R[i]] );
                    ^
  symbol:   class Tuple3
  location: class Main
Main.java:83: error: cannot find symbol
                    Tuple3 next = new Tuple3( R[i], current.y + 1, current.z + dist[current.x][R[i]] );
                                      ^
  symbol:   class Tuple3
  location: class Main
6 errors