public void Run() { N = Input.ReadInt(); G = new Graph(N); for (int i = 0; i < N - 1; i++) { var line = Input.ReadIntArray(); int a = line[0] - 1; int b = line[1] - 1; G[a].Edges.Add(new Edge(a, b, 0)); G[b].Edges.Add(new Edge(b, a, 0)); } // ?????????????? var D = new int[N]; for (int i = 0; i < N; i++) { D[i] = Dist(i); } // ????????? int colors = D.Max() - D.Min() + 1; // ???????????? var cand = new List <int>(); for (int i = 0; i < N; i++) { if (D[i] == D.Min()) { cand.Add(i); } } if (cand.Count == 2) { long leaves = CountLeaves.Run(G, cand[0], cand[1]); Console.WriteLine("{0} {1}", colors, leaves); } else { // N >= 2 // ?????????? long leaves = CountLeaves.Run(G, cand[0]); // ??????????????? foreach (var e in G[cand[0]].Edges) { long l = CountLeaves.Run(G, cand[0], e.To); leaves = Math.Min(leaves, l); } Console.WriteLine("{0} {1}", colors, leaves); } }
public static long Run(Graph G, int c) { var CL = new CountLeaves(); CL.G = G; CL.Degrees = new long[100]; CL.Count(new Edge(-1, c, 0), 0); long ret = 1; for (int i = 0; i < CL.Degrees.Length; i++) { if (CL.Degrees[i] != 0) { ret *= CL.Degrees[i]; } } return(ret); }