QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#13288. Holiday Dormitory

統計

The school holiday has arrived... Some students have gone home, while others are being visited by old friends, making accommodation a problem. For example, if A and B are both students at the school, A is going home, and C is visiting B, but C does not know A. We assume that everyone can only sleep in the bed of someone they know directly. A possible solution would be for B to sleep in A's bed and for C to sleep in B's bed. In reality, the situation can be very complex; some people may know many students, and students at the school do not necessarily all know each other. We know there are a total of $n$ people, and we know whether each person is a student at the school, as well as whether each student at the school is going home. Determine if there exists a plan such that all students who are not going home and all visitors who have come to see them have a place to sleep.

Input

The first line contains an integer $T$, representing the number of test cases. For each test case, the first line contains an integer $n$, representing the total number of people involved. The next line contains $n$ integers, where the $i$-th integer indicates whether the $i$-th person is a student at the school ($0$ means no, $1$ means yes). The following line contains $n$ integers, where the $i$-th integer indicates whether the $i$-th person is going home ($0$ means not going home, $1$ means going home; note that if the $i$-th person is not a student at the school, this value is random and should be ignored after reading). The next $n$ lines each contain $n$ integers, where the $j$-th integer in the $i$-th line indicates whether person $i$ and person $j$ know each other ($1$ means they know each other, $0$ means they do not; the value for the $i$-th row and $i$-th column is $0$, but obviously, one can still sleep in their own bed). The relationship of knowing each other is mutual.

Output

For each test case, if a plan exists, output "^_^" (without quotes); otherwise, output "T_T" (without quotes). (Note that the output characters are half-width, with ASCII codes 94, 84, and 95 respectively.)

Constraints

  • For 30% of the data, $1 \le n \le 12$.
  • For 100% of the data, $1 \le n \le 50, 1 \le T \le 20$.

Examples

Input 1

1
3
1 1 0
0 1 0
0 1 1
1 0 0
1 0 0

Output 1

^_^

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.