using System; using System.Linq; using System.Text; using System.Collections.Generic; public class Hello{ public static Station[] stations; public static void Main(){ //標準入力の読み込み var line = System.Console.ReadLine().Split(' '); int N = int.Parse(line[0]); int M = int.Parse(line[1]); //駅の配列を作成 stations = new Station[N]; for(int i=0;i(),0); } //最大値を出力 System.Console.WriteLine(arr.Max()); } private static int CalcDistance(int now, List via, int dist){ //現在の駅から移動可能な駅を書き出す var canMoveList = new List(); foreach(var ns in stations[now].next){ if(!via.Contains(ns.id)){ canMoveList.Add(ns); } } //移動可能な駅が存在しない場合はここを終着とする int cnt = canMoveList.Count; if(cnt==0){ return dist; } //移動可能な駅へ移動して距離の最大値を取得する var arr = new int[cnt]; for(int i=0;i(via); newVia.Add(now); arr[i] = CalcDistance(canMoveList[i].id,newVia,dist+canMoveList[i].distance); } return arr.Max(); } } public class Station{ public List next = new List(); } public class NextStation{ public int id; public int distance; public NextStation(int a, int b){ this.id = a; this.distance = b; } }