Find the Hacker
All submissions for this problem are available.
In today's digital era everyone is being hacked by someone, but there are a few who are untouchables/unhackable and are considered Master Hackers.
Your task is to find these Master Hackers in the hacker community. A Master Hacker is the one who is hacking everyone else either directly or indirectly,
1. A --> B, A hacks B 2. B --> C, B hacks C ==> A --> C, A is indirectly hacking C.
A hacker can hack the same person in more than 1 way.
- The first Line contains T, the no. of test cases.
- Each Test case is as follow, first line contains two space seperated integers N and M, N specifying the no. of people in the community numbered 1...N, and M is the number of people who are being hacked by someone.
- M lines follow each line consists of two space seperated integers H Q, where H-Hacker, Q-Target which is being hacked by H.
- You need to print the index of the master hacker, if more than one exists you can output any one of them, if no such master hacker is present output -1.
Should contain all the constraints on the input data that you may have. Format it like:
- 1 ≤ T ≤ 3
- 1 ≤ N ≤ 105
- 1 ≤ M ≤ min(2 * 105, N * (N - 1) / 2)
Input: 2 3 2 1 2 2 3 5 7 2 1 1 3 2 3 2 4 4 5 5 1 5 3 Output: 1 2
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.