kosaraju's algorithm
// 1. Topological sort of original graph G
// 2. Itearte over all the vertices on reverse graph RG, and perform dfs
	  on reverse graph 
// 3. Mark all the current visited node as one component

Note: its like onion-peeling algorithm and removal of sink nodes in 
Condensed connected graph
// =======================================================

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 1;

vector<int> gr[N], grr[N];
int vis[N];
int color[N];
vector<int> order;

void dfs1(int src) {
	vis[src] = 1;

	for (auto nbr : gr[src]) {
		if (!vis[nbr]) {
			dfs1(nbr);
		}
	}

	// i am at this point, bcz i have pushed all subtree
	order.push_back(src);
}

void dfs2(int src, int comp) {
	vis[src] = 1;
	color[src] = comp;
	for (auto nbr : grr[src]) {
		if (!vis[nbr]) {
			dfs2(nbr, comp);
		}
	}

}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		gr[x].push_back(y);
		grr[y].push_back(x);
	}

	for (int i = 1; i <= n; i++) {
		if(!vis[i]){
			dfs1(i);
		}
		
	}

	reverse(order.begin(), order.end());
	memset(vis, 0, sizeof(vis));

	int comp = 1;

	for (auto x : order) {
		if (!vis[x]) {
			dfs2(x, comp++);
		}
	}

	cout << "Total SCC are " << comp - 1 << endl;

	for(int i=1;i<=n;i++){
		cout<<i<<"-->"<<color[i]<<endl;
	}

	return 0;
}

C++相关代码片段

how to kill

hello world cpp

cpp hello world

when kotlin

how to write hello world c++

fenwick tree

main function

python loop

is palindrom

subsequence

insertion sort

react cookie

data structure

Stack Modified

increment integer

496. Next Greater Element I.cpp

c++ freecodecamp course 10 hours youtube

simple interest rate

deliberation meaning

fingerprint

c++ system() from variable

operator using

unambiguous

Stream Overloading

quick_sort

hash table

graph colouring

the question for me

fname from FString

how togreper

is plaindrome

logisch oder

robot framework for loop example

spyder enviroment

pallindrome string

ue4 c++ string from fvector

interactive problem

two sum solution

interpolation search

Required Length

new expression

Targon lol

xor linked list

stack implementation

typescript

loop through array

loop array

how to point to next array using pointer c++

file exist

floating point exception

array di struct

castin in C++

varint index

how to make a instagram report bot python

windows servis from console app

add integers

listas enlazadas/ linked lists

niet werkend

bubble sort

triangle angle sum

divisor summation

rotateArray

destiny child

Populating Next Right Pointers in Each Node

cosnt cast

bucket sort

double plus overload

Z-function

binary search

permutation

linked list

Implicit conversion casting

square root

public method

tower of hanoi

selection sort

dangling pointer

hello world programming

statements

volumeof a sphere