Magic Graphs#6580

Magic Graphs

1 sekunt
64 megabaýt
Örän kyn

A -partite graph is a graph whose vertices can be partitioned into disjoint sets so that no two vertices within the same set are adjacent. In this problem we consider a special version of a -partite graph in which each disjoint set contains exactly two vertices. Let us call this graph magic graph. In what follows we characterize such magic graphs.

Let be a set of positive labels \{1, 2, 3, 4, \ldots\} and be a set of negative labels \{1', 2', 3', 4', \ldots\}. Also let L = P \cup N. A magic graph is a k-partite graph G = (V, E), where is a set of vertices and E is a set of edges. We define V = V_1 \cup V_2 \cup V_3 \cup \ldots \cup V_k, where each V_i is a subset of and |V_i| = 2. There is an edge \{l_1, l_2\} in if and only if l_1 and l_2 are in different vertex sets and l_1 and l_2 are not positive and negative labels of the same number. For instance, the following graph is a magic graph.

This graph is a tripartite magic graph. V_1 is . V_2 is \{1', 2'\}. V_3 is \{1, 2'\}. Note that multiple nodes may have the same label. For example, the node labeled in V_1 is a not the same node as the node labeled in V_3. The edges follow the rule above. For example, there are edges and \{1, 2'\} because the labels are in different vertex sets and they are not positive and negative labels of the same number. Observe that edge \{1, 1'\} does not exist because the two labels are positive and negative labels of the same number.

Given a -partite magic graph , your job is to find whether there exists a -clique in .

Giriş

The first line of input is the number of test cases T \le 10. The format of each test case is as follow.

  • The first line contains the integer (2 \le K \le 24000).

  • The following lines describe set V_i, one per line. For each line, there are two labels separated by a blank space. A positive label is represented by a positive number and a negative label by a minus sign and a positive number.

Çykyş

The output file contains only one line of strings of length in \{Y, N\}^*. That is, for each test case, if a given magic graph has a -clique, print , otherwise, print .

Mysallar

1-nji mysal

Loading
Loading