Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
using namespace std; const int maxn = 1e5 + 10; int n, m; vector
graph[maxn]; int discovarable_time[maxn]; int low_link[maxn]; bool on_stack[maxn]; int cycles = 0; int current_time = 0; void dfs(int node) { static stack
st; discovarable_time[node] = current_time; low_link[node] = current_time; current_time++; st.push(node); on_stack[node] = true; for(int i = 0; i < (int) graph[node].size(); i++) { int neighbour = graph[node][i]; if(discovarable_time[neighbour] == -1) { dfs(neighbour); low_link[node] = min(low_link[node], low_link[neighbour]); } else if(on_stack[neighbour]) { low_link[node] = min(low_link[node], discovarable_time[neighbour]); } } if(discovarable_time[node] == low_link[node]) { while(!st.empty()) { int t = st.top(); st.pop(); on_stack[t] = false; cout << t + 1 << " "; if(t == node) { break; } } cout << endl; } } void SCC() { for(int i = 0; i < maxn; i++) { discovarable_time[i] = -1; on_stack[i] = 0; } for(int i = 0; i < n; i++) { if(discovarable_time[i] == -1) { dfs(i); } } } int main() { cin >> n >> m; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); } SCC(); return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)