using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; this.SetTree(); int queryCount = int.Parse(Reader.ReadLine()); for(int i=0; i q = new Queue(); this.Root = new TreeNode(0); this.NodeList[0] = this.Root; q.Enqueue(0); while (q.Count > 0) { int next = q.Dequeue(); this.NodeList[idx] = this.NodeList[next].AddChild(new TreeNode(idx)); q.Enqueue(idx); idx++; if(idx > max) { break; } this.NodeList[idx] = this.NodeList[next].AddChild(new TreeNode(idx)); q.Enqueue(idx); idx++; if(idx > max) { break; } } } public TreeNode[] NodeList; public TreeNode Root; public class TreeNode { public TreeNode Parent; public TreeNode Left; public TreeNode Right; public int ID; public TreeNode(int id) { this.ID = id; } public TreeNode AddChild(TreeNode cld) { if(this.Left == null) { this.Left = cld; } else { this.Right = cld; } cld.Parent = this; return cld; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 21 14 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }