F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Funny Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 463    Accepted Submission(s): 236


Problem Description
Bob has an array \(\{a_1,a_2,\dots,a_n\}\), each element is an integer between 1 and \(n\). Bob also has \(m\) functions whose domain and codomain are both \(\{1, 2, \dots, n\}\). Bob and Alice begin to play a game on the array. Alice plays first. For each turn, the player can choose a function \(f\) and make every \(a_i\ (1 \le i \le n)\) become \(f(a_i)\). For example, the array is \(\{1, 1, 2, 4, 5\}\) and \(f(1) = 1, f(2) = 3, f(3) = 4, f(4) = 1, f(5) = 2\). Then after the operation the array will become \(\{1, 1, 3, 1, 2\}\). If all the element in the array is same, then Alice wins and the game stops. So you can see that Bob's goal is to stop Alice. Suppose that both Alice and Bob play optimally. Alice wants to know if she can always win no matter what the array looks like.
 

Input
There are multiple test cases. The first line of input contains an integer \(T\ (1 \le T \le 200)\), indicating the number of test cases. For each test case: The first line contains two integers \(n\) and \(m\) (\(1 \le n, m \le 100\)), indicating the element in the array and the number of functions. In the next \(m\) lines, each contains \(n\) integers \(f(1), f(2), \dots, f(n)\) (\(1 \le f(i) \le n, 1 \le i \le n\)).
 

Output
For each case, output "YES"(without quotes) if Alice can always win no matter what the array looks like, otherwise output "NO"(without quotes).
 

Sample Input
2 5 1 1 3 4 1 2 5 1 2 3 4 5 1
 

Sample Output
YES NO
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 16:48:15, Gzip enabled