Rhezo and HackerEarth
Practice
4.1 (19 votes)
Approved
Depth first search
Easy
Graphs
Ready
Problem
46% Success 4294 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Rhezo has just joined HackerEarth as an intern. Like most companies, HackerEarth too has a lot of computers and some departments. For efficient communication, it is very important that every computer can connect with each other in the same department, with the connection not being necessarily direct.

When each computer can connect with any other computer in the same department, that department is said to be happy. Initially all departments are happy.

Rhezo's friend Lonewolf wants to have some fun, and will cut some connection between any two computers for Q days. You being the Happy Manager of HackerEarth, need to tell for each of the Q days, if some department becomes unhappy.

Input:

First line contains 2 integers N and M, denoting the number of computers and number of wire connections at HackerEarth. Each of the next M lines contain 2 integers \(A_i\) and \(B_i\), meaning that computer number \(A_i\) is connected to computer number \(B_i\).

Next line contains an integer Q, denoting the number of days Lonewolf cuts a connection between 2 computers at HackerEarth. Each of the next Q lines contain a single integer P, which means that connection between computer \(A_p\) and computer \(B_p\) is cut.

Output:

For each of the Q days, you need to tell whether any department is unhappy or not. If all departments are happy, print "Happy"(without quotes), else print "Unhappy"(without quotes).

Constraints:

\(1 \le N ,M \le 10^{5} \)

\(1 \le A_i, B_i \le N\)

\(1 \le P \le M\)

\(1 \le M \le max(10^{5},N \cdot (N-1) / 2)\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
No similar problems found