using System; using System.Collections; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int matiCount = int.Parse(Reader.ReadLine()); this.Taizaihi = new int[matiCount]; for(int i=0; i()); } road[inpt[0]].Add(inpt[1], inpt[2]); if(!road.ContainsKey(inpt[1])) { road.Add(inpt[1], new Dictionary()); } road[inpt[1]].Add(inpt[0], inpt[2]); } int ans = int.MaxValue ; for(int i=1; i= 0 && cost2 >= 0 && cost3 >= 0) { subTotal = cost1 + cost2 + cost3 + Taizaihi[i] + Taizaihi[j]; ans = Math.Min(ans, subTotal); } } } } Console.WriteLine(ans); } Dictionary> moveDic = new Dictionary>(); private int GetCost(int fromMati, int toMati) { if(!moveDic.ContainsKey(fromMati)) { moveDic.Add(fromMati, new Dictionary()); } if(moveDic[fromMati].ContainsKey(toMati)) { return moveDic[fromMati][toMati]; } Nullable[] localDic = new Nullable[this.Taizaihi.Length]; Queue task = new Queue(); task.Enqueue(fromMati); localDic[fromMati] = 0; while (task.Count> 0) { int pos = task.Dequeue(); if(this.road.ContainsKey(pos)) { foreach (int key in this.road[pos].Keys) { if(localDic[key] == null || localDic[key].Value > localDic[pos].Value + road[pos][key]) { localDic[key] = localDic[pos].Value + road[pos][key]; task.Enqueue(key); } } } } for(int i=0; i()); moveDic[i][fromMati] = val; } } } return (localDic[toMati] == null)?(-1):(localDic[toMati].Value); } private Dictionary> road = new Dictionary>(); private int[] Taizaihi; public class Reader { private static String InitText = @" "; private static System.IO.StringReader sr = null; public static bool IsDebug = true; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new System.IO.StringReader(InitText.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