You are given a problem to solve as a problem c S P Formulate and implement CSP. Suppose…
- User
You are given a problem to solve as a problem c S P Formulate and implement CSP. Suppose we have a graph whose nodes can be any triangle, square, pentagon, hexagon or circle. We want to assign a number between 1 and 9 to each node of this graph if the following conditions are met:
The number assigned to each triangular node should be equal to the leftmost digit of the product of the numbers assigned to its adjacent nodes. The number assigned to each node in the form of a square should be equal to the rightmost digit of the product of the numbers assigned to its adjacent nodes. The number assigned to each node in the shape of a pentagon should be equal to the leftmost digit of the sum of the numbers assigned to its adjacent nodes. The number assigned to each node in the shape of a hexagon should be equal to the rightmost digit of the sum of the numbers assigned to its adjacent nodes. There is no limit to circular nodes. The figure shows a sample graph with numbers assigned to each node. You have been asked to find the numbers assigned to the nodes of the graph by getting the specifications of the graph.
Fig
input The first line of input number T T is the number of tests. The first line of each test, including numbers V V and E E is the first one indicating the number of nodes and the second indicating the number of edges of the graph.
In the next line V The character V comes from one of the characters T for triangle, S for square, P for pentagon, H for hexagon, and C for circle, separated by a space. i iam, the shape of the knot i Specifies the ith (0 ≥ i i).
after that, E E line comes in the form of i j. which shows the edge between the nodes i iam and node J There is jam. The input sample corresponding to the figure is given below.
output For each test, there is one line of output that includes V V is a number between 1 and 9, separated by a space, and the number i i, the value assigned to the node i It shows i.
Example Sample entry 1 1 9 8 C P H S S H H T C 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 Plain text Sample output 1 9 1 7 6 8 3 5 2 4 c++
- Assistant