01tree
면접 대비시간 제한1초메모리 제한2048 MB
이진 트리에서 기억과 일치하는 모든 시작 상태와 끝 상태 쌍의 최소 변환 시간 합을 1e9+7로 나눈 나머지를 구한다.
문제
There is a tree with nodes. Every node has a value of 0 or 1.
In one second, you can choose two adjacent nodes with the same value and flip both values.
Given some starting state and some ending state, you will always spend the least number of seconds transforming the starting state into the ending state. If it is impossible to transform the starting state into the ending state, you just skip it (so you spend 0 seconds).
The issue is that, for some nodes, you do not remember the value on them (in either the starting state, the ending state, or both). Over all pairs of (starting state, ending state) that are consistent with your memory, find the total amount of time that it will take to transform from the starting state to the ending state. Print this value modulo .
입력
The first line contains an integer , the number of test cases (). The test cases follow.
The first line of each test case contains one integer () denoting the size of the tree.
Then lines follow, each containing two integers and , denoting the edge that connects and in the tree.
The following line contains a string of length consisting of characters "0", "1", and "?". This string denotes your memory of the starting state: "0" and "1" represent the value of the node, and "?" represents that you do not remember the value of the node.
The following line contains a string of length denoting your memory of the ending state. It follows the same format as the starting state.
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, print a line with a single integer: the answer modulo .