using System; using System.IO; using System.Linq; using System.Collections.Generic; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int nodeCount = inpt[0]; int pathCount = inpt[1]; for (int i = 0; i < pathCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int[][] tmp = new int[][] { inpt, inpt.Reverse().ToArray() }; foreach(int[] lst in tmp) { if(!Path.ContainsKey(lst[0])) { Path.Add(lst[0],new Dictionary()); } Path[lst[0]].Add(lst[1], true); } } Dictionary>>> dic = new Dictionary>>>(); foreach(int key1 in Path.Keys) { if(Path[key1].Count < 2) { continue; } int[] key1ToList = Path[key1].Keys.ToArray(); for (int i = 0; i < key1ToList.Length - 1;i++) { for (int j = i + 1; j < key1ToList.Length;j++) { if(Path[key1ToList[i]].ContainsKey(key1ToList[j])) { continue; } if(!Path.Any(a=>a.Key != key1 && a.Value.ContainsKey(key1ToList[i]) && a.Value.ContainsKey(key1ToList[j]))) { continue; } int[] key2List = Path.Where(a => a.Key != key1 && a.Value.ContainsKey(key1ToList[i]) && a.Value.ContainsKey(key1ToList[j])).Select(a => a.Key).ToArray(); foreach(int key2 in key2List) { if(Path[key2].ContainsKey(key1)) { continue; } int[] tmp = new int[]{key1, key2, key1ToList[i], key1ToList[j]}.OrderBy(a=>a).ToArray(); if(!dic.ContainsKey(tmp[0])) { dic.Add(tmp[0], new Dictionary>>()); } if(!dic[tmp[0]].ContainsKey(tmp[1])) { dic[tmp[0]].Add(tmp[1], new Dictionary>()); } if(!dic[tmp[0]][tmp[1]].ContainsKey(tmp[2])) { dic[tmp[0]][tmp[1]].Add(tmp[2], new Dictionary()); } dic[tmp[0]][tmp[1]][tmp[2]][tmp[3]] = true; } } } } int ans = dic.Select(a => a.Value.Select(b => b.Value.Select(c => c.Value.Count()).Sum()).Sum()).Sum(); Console.WriteLine(ans); } private Dictionary> Path = new Dictionary>(); public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 8 17 0 3 0 4 0 6 1 2 1 6 2 4 2 5 2 7 3 4 3 5 3 6 4 5 4 6 4 7 5 6 5 7 6 7 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }