diff --git a/README.md b/README.md index 400b1e9322..94d2a09fc7 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,7 @@ _If you like this project, please leave me a star._ ★ |1200|[Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1200.java) | [:tv:](https://www.youtube.com/watch?v=mH1aEjOEjcQ)|Easy|| |1198|[Find Smallest Common Element in All Rows](https://leetcode.com/problems/find-smallest-common-element-in-all-rows/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1198.java) | [:tv:](https://www.youtube.com/watch?v=RMiofZrTmWo)|Easy|| |1196|[How Many Apples Can You Put into the Basket](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1196.java) | [:tv:](https://www.youtube.com/watch?v=UelshlMQNJM)|Easy|| +|1192|[Critical Connections in a Network](https://leetcode.com/problems/critical-connections-in-a-network/)|[C++](../master/cpp/_1192.cpp) | |Hard|DFS| |1190|[Reverse Substrings Between Each Pair of Parentheses](https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1190.java) | |Medium|Stack| |1189|[Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1189.java) |[:tv:](https://youtu.be/LGgMZC0vj5s) |Easy|| |1185|[Day of the Week](https://leetcode.com/problems/day-of-the-week/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1185.java) | |Easy|| diff --git a/cpp/_1192.cpp b/cpp/_1192.cpp new file mode 100644 index 0000000000..150f7d12b7 --- /dev/null +++ b/cpp/_1192.cpp @@ -0,0 +1,40 @@ +// 1192. Critical Connections in a Network + + +class Solution { +public: + vector rank,lowest; + vector> graph,res; + + int solve(int node,int depth,int parent){ + if(rank[node]>=0) + return rank[node]; + rank[node]=depth; + int ans = depth; + for(auto neighbour:graph[node]){ + if(parent==neighbour) + continue; + int back_depth = solve(neighbour,depth+1,node); + if(back_depth>depth){ + res.push_back({node,neighbour}); + } + ans = min(ans,back_depth); + } + rank[node]=ans; + return ans; + } + + vector> criticalConnections(int n, vector>& connections) { + rank = vector(n,-2); + lowest=vector(n,INT_MAX); + graph = vector>(n); + + for(auto i:connections){ + graph[i[0]].push_back(i[1]); + graph[i[1]].push_back(i[0]); + } + + solve(0,0,-1); + return res; + } +}; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy