✅C++ |  ✅DFS | ✅Tarjans Algorithm |  ✅Bridges |  ✅Explanation through comments
Please upvote if this solution is helpful :)\nTC- O(N+E), SC-O(N)\nN - nodes of the graph, E- edges of the graph\n\n\n\n\n\nclass Solution {\npublic:\n    //use
**Please upvote if this solution is helpful :)**\n**TC- O(N+E), SC-O(N)**\n*N - nodes of the graph, E- edges of the graph*\n\n![image](https://assets.leetcode.com/users/images/68d99ffa-1224-4a8b-9323-778535ac7fa9_1652869640.0461094.jpeg)\n\n\n```\nclass Solution {\npublic:\n    //use find the bridges in a graph approach to get all critical connections\n\t//Tarjans Algorithm / DFS\n    void dfs(int node, int parent, vector<int> &tin, vector<int> &low, vector<int> &vis, vector<int> graph[], vector<vector<int>> &ans, int &time)\n    {\n        //when we visite node first time, tin and low of the node are equal to the time\n        tin[node]=low[node]=time++;\n        vis[node] = 1; //mark node as visited\n        \n        for(auto it : graph[node])\n        {\n            if(it == parent) continue; //to avoid backtracking\n            \n            //if node is not visited, call the dfs function\n            if(!vis[it])\n            {\n                dfs(it, node, tin, low, vis, graph, ans, time);\n                \n                //when we return, low of the node is equal to the minimum of low of its child and low of itself\n                low[node] = min(low[node], low[it]);\n                \n                //when we get low of child is greater than tin of the node\n                //it means there is only path to cover child that\'s why {node, it} will be our critical connections or bridge \n                if(low[it] > tin[node])\n                    ans.push_back({node, it});\n            }\n            \n            //if node is already visited and tin of the child is less than the low of itself\n            //we assign tin of the child to the low of the node\n            else\n                low[node] = min(low[node], tin[it]);\n            \n        }\n    }\n    vector<vector<int>> criticalConnections(int n, vector<vector<int>>& connections) \n    {\n        //tin - time of insertion at the node\n        //low - lowest time of insertion at the node\n        //vis - mark visited node \n        vector<int> tin(n, -1), low(n, -1), vis(n, 0);\n        vector<vector<int>> ans;\n        vector<int> graph[n]; //stores connections in the form of graph\n        int time=0;\n        \n        for(auto it: connections)\n        {\n            graph[it[0]].push_back(it[1]);\n            graph[it[1]].push_back(it[0]);\n        }\n        \n        //call dfs function\n        dfs(0, -1, tin, low, vis, graph, ans, time);\n        return ans;\n    }\n};\n```
['Depth-First Search', 'Graph', 'C', 'C++']