import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static int N, M; static int stayCost[]; static int moveCost[][]; public static void main(String[] args) { try (Scanner scan = new Scanner(System.in)) { N = scan.nextInt(); stayCost = new int[N]; for(int i=0; i q = new LinkedList<>(); q.add(start); while(true) { Integer now = q.poll(); if(now == null) break; flag[now] = true; for(int i=0; i 0 && flag[i] == false) { int tmp = minCost[now] + moveCost[now][i]; minCost[i] = Math.min(minCost[i], tmp); q.add(i); } } } return minCost[goal]; } }