C++ || DFS || Find bridges
\tYou can search "find bridges graph" in youtube or google to understand algorithm, that is easiest way.\n\tclass Solution {\n\tpublic:\n\t\tvector> ans;\n\t\tv
\tYou can search "find bridges graph" in youtube or google to understand algorithm, that is easiest way.\n\tclass Solution {\n\tpublic:\n\t\tvector<vector<int>> ans;\n\t\tvector<vector<int>> graph;\n\n\t\tvector<int> firstTime, minTime, visited;\n\t\tint time = 1;\n\n\t\tvoid dfs(int node, int parent = -1) {\n\t\t\tfirstTime[node] = minTime[node] = time++;\n\t\t\tvisited[node] = true;\n\n\t\t\tfor(auto& child : graph[node]) {\n\t\t\t\tif(child == parent)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tif(!visited[child]) \n\t\t\t\t\tdfs(child, node);\n\n\t\t\t\tminTime[node] = min(minTime[child], minTime[node]);\n\n\t\t\t\tif(firstTime[node] < minTime[child])\n\t\t\t\t\tans.push_back({node, child});\n\t\t\t}\n\t\t}\n\n\t\tvector<vector<int>> criticalConnections(int n, vector<vector<int>>& connections) {\n\t\t\tfirstTime.resize(n), minTime.resize(n), visited.resize(n), graph.resize(n);\n\t\t\tfor(auto& edge : connections) {\n\t\t\t\tint nodeA = edge[0], nodeB = edge[1];\n\t\t\t\tgraph[nodeA].push_back(nodeB);\n\t\t\t\tgraph[nodeB].push_back(nodeA);\n\t\t\t}\n\t\t\tdfs(0);\n\t\t\treturn ans;\n\t\t}\n\t};
['Depth-First Search', 'C']