using System; using System.Collections.Generic; using System.Text; public class Program { public void Proc(){ Reader.IsDebug = false; int matiCount = int.Parse(Reader.ReadLine()); this.Money = int.Parse(Reader.ReadLine()); int roadCount = int.Parse(Reader.ReadLine()); int[] inpt = Reader.GetInt(); for(int i=0; i()); } RoadDic[r.From].Add(r); } inpt = Reader.GetInt(); for(int i=0; i> RoadDic = new Dictionary>(); private Dictionary dic = new Dictionary(); private int GetAns(int fromMati, int ToMati, int remain) { string key = fromMati + "#" + ToMati + "#" + remain; if(dic.ContainsKey(key)) { return dic[key]; } if(fromMati == ToMati) { return 0; } if(remain < 0) { return -1; } int ans = int.MaxValue; foreach(Road r in RoadDic[fromMati]) { if(r.Cost <= remain) { int subAns = this.GetAns(r.To, ToMati, remain - r.Cost); if(subAns >= 0) { ans = Math.Min(ans, subAns + r.Time); } } } if(ans == int.MaxValue) { ans = -1; } dic.Add(key, ans); return ans; } private List RoadList = new List(); public class Road { public int From; public int To; public int Cost; public int Time; } private int Money = 0; public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } } class Reader { public static bool IsDebug = true; private static System.IO.StringReader sr; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new System.IO.StringReader(initStr.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ') { string[] inpt = ReadLine().Split(delimiter); int[] ret = new int[inpt.Length]; for(int i=0; i