import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList> List = new ArrayList<>(); ArrayList triple = new ArrayList<>(); int town = sc.nextInt(); int money = sc.nextInt(); int ru = sc.nextInt(); int[] from = new int[ru]; int[] to = new int[ru]; int[] cost = new int[ru]; int[] time = new int[ru]; for(int i=0; i copy = new ArrayList<>(triple); List.add(copy); triple.clear(); for(int i=2; i<=town ;i++){//二番目の町から for(int j=0; j sub = new ArrayList<>(List.get(from[j]-1)); for(int t=0; t copy_2 = new ArrayList<>(triple); List.add(copy_2); triple.clear(); } //最短経路を取り出す triple = List.get(town-1); if(triple.isEmpty()){ System.out.println(-1); }else{ int c; ArrayList sort = new ArrayList(); for(int i=0; i