in the example given should’nt the answer be no because 2 nodes are connected only if they are same, but if only 1 edge is there how can there be a 3 letter word?
I dont understand the question
It’s yes, because you can give like XXZ , now 1 and 2 are connected but 3rd is not connected.
Can you please help me with the logic. I do not understand how to solve this.
First observation is that, if two nodes, u and v are not connected, then one of them is “x” and another one is “z”. Second observation is that if is a set of nodes with value “x”, and set is a set of nodes with value “z”, then interchanging them will not change the encrypted graph, i.e. assign value “z” to set and value “x” to set . So first we will search for a pair of nodes, u and v , which are not connected, assign one of them to “x” and another to “z”. Now for the rest of the nodes, if a node, w is connected to both u and v , assign value “y” to it. If a node, w is connected to node u only, then assign value “x” to it. If a node, w is connected to node v only, then assign value “z” to it. Now since you have assigned values to all of the nodes, for every pair of nodes, check whether it satisfies the rules of encryption. If it does not, then answer is NO.
The code to implement this https://ide.codingblocks.com/s/340582
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.