Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add 1192 (cpp)#108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
SysSn13 wants to merge1 commit intofishercoder1534:master
base:master
Choose a base branch
Loading
fromSysSn13:master
Open
Show file tree
Hide file tree
Changes fromall 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 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionscpp/_1192.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff 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;
}
};

[8]ページ先頭

©2009-2025 Movatter.jp