Exemplo n.º 1
0
        public static void Test()
        {
            Solution s = new Solution();

            //[[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]]
            var res = s.CountSubTrees(7,
                                      new int[][]
            {
                new[] { 0, 1 },
                new[] { 0, 2 },
                new[] { 1, 4 },
                new[] { 1, 5 },
                new[] { 2, 3 },
                new[] { 2, 6 },
            },
                                      "abaedcd"
                                      );

            res.PrintList();

            ////Input: n = 4, edges = [[0,1],[1,2],[0,3]], labels = "bbbb"
            //res = s.CountSubTrees(4,
            //	new int[][]
            //	{
            //		new[] {0, 1},
            //		new[] {1, 2},
            //		new[] {0, 3},
            //	},
            //	"bbbb"
            //);
            //res.PrintList();

            ////Input: n = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = "aabab"
            //res = s.CountSubTrees(5,
            //	new int[][]
            //	{
            //		new[] {0, 1},
            //		new[] {0, 2},
            //		new[] {1, 3},
            //		new[] {0, 4},
            //	},
            //	"aabab"
            //);
            //res.PrintList();

            ////Input: n = 6, edges = [[0, 1],[0,2],[1,3],[3,4],[4,5]], labels = "cbabaa"
            //res = s.CountSubTrees(6,
            //	new int[][]
            //	{
            //		new[] {0, 1},
            //		new[] {0, 2},
            //		new[] {1, 3},
            //		new[] {3, 4},
            //		new[] {4, 5},
            //	},
            //	"cbabaa"
            //);
            //res.PrintList();

            ////Input: n = 7, edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,6]], labels = "aaabaaa"
            //res = s.CountSubTrees(7,
            //	new int[][]
            //	{
            //		new[] {0, 1},
            //		new[] {1, 2},
            //		new[] {2, 3},
            //		new[] {3, 4},
            //		new[] {4, 5},
            //		new[] {5, 6},
            //	},
            //	"aaabaaa"
            //);
            //res.PrintList();

            ////4 [[0,2],[0,3],[1,2]] "aeed"
            //res = s.CountSubTrees(4,
            //	new int[][]
            //	{
            //		new[] {0, 2},
            //		new[] {0, 3},
            //		new[] {1, 2},
            //	},
            //	"aeed"
            //);
            //res.PrintList();

            //string f =
            //	@"E:\GS2018\E\Yang\Program\Git\GitYang\YangPracticeLeetCode\YangPracticeLeetCode\YangPracticeLeetCode\TestData\_5465_1.txt";
            //string[] fs = File.ReadAllText(f).Split(new[] { "\r\n" }, StringSplitOptions.None);

            //List<int[]> iss = new List<int[]>();
            //string[] ls = fs[1].Substring(1, fs[1].Length - 2).Replace("[", "").Replace("]", "").Split(',');

            //for (int i = 0; i < ls.Length - 1;)
            //{
            //	iss.Add(new int[] { Convert.ToInt32(ls[i]), Convert.ToInt32(ls[i + 1]) });
            //	i += 2;
            //}

            //DateTime dt = DateTime.Now;
            //var res = s.CountSubTrees(Convert.ToInt32(fs[0]),
            //	iss.ToArray(),
            //	fs[2].Replace("\"", "")
            //);
            //res.PrintList();



            //Console.WriteLine(DateTime.Now.Subtract(dt).TotalMilliseconds);
        }