import java.util.Arrays; import java.util.Scanner; public class ShortCut { public static void main(String[] args) { ShortCut p = new ShortCut(); } public ShortCut() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int c = sc.nextInt(); int v = sc.nextInt(); Edge[] e = new Edge[v]; for(int i=0;i= 0) dp[e.t][j] = Math.min(dp[e.t][j], Math.min(dp[e.s][j-e.y] + e.m, dp[e.t][j-1])); } } int res = INF; for(int i=1;i<=c;i++){ res = Math.min(res, dp[n][i]); } if(res >= INF) System.out.println(-1); else System.out.println(res); } private class Edge implements Comparable{ int s; int t; int y; int m; public Edge(int s, int t, int y, int m) { this.s = s; this.t = t; this.y = y; this.m = m; } public Edge() { } @Override public int compareTo(Edge o) { if(this.s != o.s) return this.s - o.s; else return this.t - o.t; } } }