Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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||
Expand Down
40 changes: 40 additions & 0 deletions cpp/_1192.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 1192. Critical Connections in a Network


class Solution {
public:
vector<int> rank,lowest;
vector<vector<int>> 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<vector<int>> criticalConnections(int n, vector<vector<int>>& connections) {
rank = vector<int>(n,-2);
lowest=vector<int>(n,INT_MAX);
graph = vector<vector<int>>(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;
}
};