TCCC '24 Jan P3 - Hamlet Brain Problem

View as PDF

Submit solution

Points: 10
Time limit: 1.5s
Java 8 3.0s
Python 3 3.0s
Memory limit: 128M

Author:
Problem type

“King: Love! His affections do not that way tend; Nor what he spake, though it lakc’d form a little, was not like madness. There’s something in his soul O’er which his melancholy sits on brood, And I do doubt the hatch and the disclose Will be some danger: which for to prevent, I have in quick determination Thus set it down: he shall with speed to England For the demand of our neglected tribute: Haply, the seas, and countries different With variable objects shall expel This something-settled matter in his heart, Whereon his brains still beating puts him thus from fashion of himself” (Shakespeare, 3.1.164-177).

Hamlet’s plan is proven futile as King Claudius quickly identifies that Hamlet is still sane. This discovery leads Claudius to want an investigation into Hamlet, backfiring Hamlet’s plan. The plan lacks logic and proper thought, indicating an ulterior influence taking his focus, such as his father's death or revenge. In the path of revenge, Hamlet struggles to keep his thoughts together, as shown by the crude plan. With the Id in control, Hamlet abandons social norms and logic, which causes him to act in a manner that negatively affects himself and others.

The superego within Hamlet is in desperate need of assistance. The id has shut the superego down, and the superego requests that you aid in the decision process for every thought Hamlet has. Since the superego is all about logic, it has decided to test your thinking skills to ensure you are fit for this job. Inside Hamlet’s brain, constantly new neuron connections are forming. Your job is to keep track of these bidirectional connections and to query if two neurons are connected. There may be multiple connections between two neurons. Each query follows the format of 3 integers, t, a, b. If t = 1, then join neurons a and b. Otherwise, if t = 2, print connected if a connection exists or not connected if it does not.

Fast I/O in Java and Python is recommended

Input Specifications

The first line contains integer N (1 \le N \le 10^5), the number of neurons, numbered (1, 2, ... , n), and integer Q (1 \le Q \le 5 * 10^5) representing the number of queries.

The next Q lines are the queries to process.

Output Specifications

Output connected if two nodes are connected or not connected if they are not, if t = 1 output nothing.

Sample input 1

5 5
1 1 2
1 2 3
2 1 3
1 4 5
2 3 5

Sample output 1

connected
not connected

Sample input 1 explanation

After the initial connections of 1, 2, and 3, we see that neurons 1 and 3 are connected, so output connected

Neurons1

After connecting neurons 4 and 5, neurons 3 and 5 are not connected, therefore output not connected

Neurons2


Comments

There are no comments at the moment.