Clean Java Solution With Explanation!!! Great Question!
\nclass Solution {\n    // We record the timestamp that we visit each node. For each node, we check every neighbor except its parent and return a smallest times
```\nclass Solution {\n    // We record the timestamp that we visit each node. For each node, we check every neighbor except its parent and return a smallest timestamp in all its neighbors. If this timestamp is strictly less than the node\'s timestamp, we know that this node is somehow in a cycle. Otherwise, this edge from the parent to this node is a critical connection\n    public List<List<Integer>> criticalConnections(int n, List<List<Integer>> connections) {\n        List<Integer>[] graph = new ArrayList[n];\n        for (int i = 0; i < n; i++) graph[i] = new ArrayList<>();\n        \n        for(List<Integer> oneConnection :connections) {\n            graph[oneConnection.get(0)].add(oneConnection.get(1));\n            graph[oneConnection.get(1)].add(oneConnection.get(0));\n        }\n        int timer[] = new int[1];\n        List<List<Integer>> results = new ArrayList<>();\n        boolean[] visited = new boolean[n];\n        int []timeStampAtThatNode = new int[n]; \n        criticalConnectionsUtil(graph, -1, 0, timer, visited, results, timeStampAtThatNode);\n        return results;\n    }\n    \n    \n    public void criticalConnectionsUtil(List<Integer>[] graph, int parent, int node, int timer[], boolean[] visited, List<List<Integer>> results, int []timeStampAtThatNode) {\n        visited[node] = true;\n        timeStampAtThatNode[node] = timer[0]++;\n        int currentTimeStamp = timeStampAtThatNode[node];\n        \n        for(int oneNeighbour : graph[node]) {\n            if(oneNeighbour == parent) continue;\n            if(!visited[oneNeighbour]) criticalConnectionsUtil(graph, node, oneNeighbour, timer, visited, results, timeStampAtThatNode);\n            timeStampAtThatNode[node] = Math.min(timeStampAtThatNode[node], timeStampAtThatNode[oneNeighbour]);\n            if(currentTimeStamp < timeStampAtThatNode[oneNeighbour]) results.add(Arrays.asList(node, oneNeighbour));\n        }\n        \n        \n    }\n    \n}\n```\nListed below are all Questions asked In Concise Manner:\n1. Why do we write a special case for parent?before iterating every child ,visited[parent] becomes true.\nAns: he reason for writing a special condition for checking parent is that, I don\'t want the timing of my currently node\'s parent to update my current node\'s timing which will always be less than my current node which would ultimately lead to result being populated with all the connections in the graph. Let me know if you understand the explanation otherwise I can explain you the same with an example. \n\n2.  We don\'t need "visited[]". If timestampAtThatNode[I] == 0, then it is not visited, given timer[] start with 1.\nAns: Yes, that\'s a great idea we can go ahead with that as well!\nWill save memory of visited array.\n\n3. why the timer is an array with one value in it? what if we use a integer to store it ?\nAns: Yes, you can also use one int value for the timer but generally in these types of graph problems there are a couple of timers some time and it doesnt make sense have different fields every time but in this problem it doesn\'t matter. You can use anything!\n\n4. How would you recommend that we maintain the order of the input nodes? (For the case: Input: n = 4, connections = [[0,1],[1,2],[2,0],[1,3]] Output: [[1,3]]\n[[3,1]] is also accepted. How could we preserve the input order, i.e. only return [1,3] and not [3,1])\nAns: First of all, the entire graph is undirected which means that the order does not matter!\nBut even then if you need to preserve the order the easiest way is to traverse the input connections for every result connection to check if it is in the same order which is there in the input if not we reverse the order. Its complexity will be order of (input connections, result connection)\nEasier way will be to add all the input connections to hashset. While adding a connection to result we just check whether that connection is in the set. If it is we add it as it is, if not we will reverse it and add it. This will be order of number of connections in the result.\n\n5. why if(currentTimeStamp < timeStampAtThatNode[oneNeighbour]) other than if(currentTimeStamp > timeStampAtThatNode[oneNeighbour]) ?\ncurrentTimeStamp means the timestamp of current node, if the timestamp of its neighbor is less than its own timestamp, then there\'s a critical connection. Am I understanding correct ?\nAns : A critical connection (A-B) where A is the current node and B is the neighbour of A in the DFS traversal is given by a connection when A is visited before its neighbour(B). Which means that only way to go to B is through A. Now, if B is visited before A through some other node\'s DFS traversal and updated the visited time of B to a value lower than visited time of A it means that there is a way to reach B which will not go through A. So edge A-B is not a critical connection because even after removing edge A-B , B will not be isolated.\n\n
[]