Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class t112633 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int[][] matrix = new int[n][n];
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- matrix[i][j] = in.nextInt();
- }
- }
- in.nextLine();
- String[] a = in.nextLine().split(" ");
- int s = 0;
- for (int i = 1; i < a.length; i++) {
- int from = Integer.parseInt(a[i - 1]) - 1;
- int to = Integer.parseInt(a[i]) - 1;
- if (matrix[from][to] != 0)
- s += matrix[from][to];
- else {
- System.out.println(0);
- return;
- }
- }
- System.out.println(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement