本题来源于：2013 年 ACM-ICPC 中国成都省级编程大赛
给定一棵有 个节点的树, 有 次询问, 每次询问两点间的最短路径上的最长连续严格递增子序列。
For a sequence , and a pair of integers , if and , then the sequence is a CIS (Continuous Increasing Subsequence). The longest CIS of a sequence is called the LCIS (Longest Continuous Increasing Subsequence).
Now we consider a tree rooted at node . Nodes have values. We have queries, each with two nodes and . You have to find the shortest path from to . And write down each nodes' value on the path, from to , inclusive. Then you will get a sequence, and please show us the length of its LCIS.
The first line has a number (), indicating the number of test cases.
For each test case, the first line is a number (), the number of nodes in the tree.
The second line comes with numbers , describing the value of node to node . ()
The third line comes with numbers , describing the father nodes of node to node . Node is the root and will have no father.
Then comes a number , it is the number of queries. ()
For next lines, each with two numbers and . As described above.
For test case , output
Case at the first line.
Then output lines, each with an answer to the query.
There should be a blank line BETWEEN each test case.
1 5 1 2 3 4 5 1 1 3 3 3 1 5 4 5 2 5
Case #1: 3 2 3