using System; using System.Collections.Generic; using System.IO; namespace D8._1 { class Program { static void Main(string[] args) { if (args.Length < 1) return; if (File.Exists(args[0]) == false) return; var file = File.OpenText(args[0]); var text = file.ReadToEnd(); var all = new List(text.Split(" ")); int result = 0; var root = getNode(all, ref result); Console.WriteLine($"Result is : {result}"); } static Node getNode(List all, ref int result) { var node = new Node(); (int children, int metadatas) header = (int.Parse(all[0]), int.Parse(all[1])); all.RemoveAt(0); all.RemoveAt(0); for (int j = 0; j < header.children; j++) { var childnode = getNode(all, ref result); node.Children.Add(childnode); } for (int j = 0; j < header.metadatas; j++) { int meta = int.Parse(all[0]); all.RemoveAt(0); node.Meta.Add(meta); result += meta; } return node; } } class Node { public List Meta { get; set; } public List Children { get; set; } public Node() { Meta = new List(); Children = new List(); } } }