Magic Graphs
Time limit2sMemory limit64 MB
Pick one label from each of K pairs so that no two chosen labels are the positive and negative of the same number.
Problem
A k-partite graph is a graph whose vertices split into disjoint sets so that no two vertices inside the same set are adjacent. This problem only deals with a special k-partite graph in which every set holds exactly two vertices. Call such a graph a magic graph.
Let be the set of positive labels, let be the set of negative labels, and let . A magic graph is a k-partite graph with , where every is a subset of with . The edge exists only when both conditions hold. First, and belong to different sets. Second, and are not the positive and the negative label of the same number.
For example, look at the tripartite magic graph with , and . Two vertices with the same label in different sets are different vertices, so the vertex labeled 1 in is not the vertex labeled 1 in . The edges follow the rule above. The edges and exist because the two labels sit in different sets and are not the positive and the negative label of one number. The edge does not exist, because 1 and are the positive and the negative label of the same number.
Given a k-partite magic graph , decide whether has a clique of size .
Input
The first line contains the number of test cases , where .
Each test case has the following format.
- The first line contains the integer , where .
- Each of the next lines describes one set and holds two labels separated by a single space. A positive label is written as a positive number, and a negative label as a minus sign followed by a positive number.
Output
Print one line with a string of length made of the characters Y and N. The -th character answers the -th test case: Y if the given magic graph has a clique of size , and N otherwise.