The kosaraju algorithm requires directed graph strongly connected components.
Take a look, here
Detailed description.
# Include <stdio. h> # include <string. h ># include <vector> using namespace STD; /* num [] records access vertex sequence STC [] records connected branch E1 of vertex [] source image e2 [] Reverse graph visited [] hash accessed vertex */const int maxn = 101; typedef vector <int> edge; edgee1 [maxn], E2 [maxn]; int num [maxn], STC [maxn], CNT; bool visited [maxn]; void DFS (INT Vex) {visited [Vex] = true; For (INT I = 0; I <e1 [Vex]. size (); I ++) {If (! Visited [e1 [Vex] [I]) {DFS (e1 [Vex] [I]);} num [CNT ++] = Vex ;} void DFS (INT Vex, const Int & ANC) {visited [Vex] = true; STC [Vex] = ANC; For (INT I = 0; I <e2 [Vex]. size (); I ++) {If (! Visited [e2 [Vex] [I]) {DFS (E2 [Vex] [I], ANC) ;}} void Init () {CNT = 0; int I, j, n, m, a, B; scanf ("% d", & N, & M); for (I = 0; I <n; I ++) {e1 [I]. clear (); E2 [I]. clear (); visited [I] = 0 ;}for (I = 0; I <m; I ++) {scanf ("% d", &, & B); e1 [A]. push_back (B); E2 [B]. push_back (a) ;}for (I = 0; I <n; I ++) {If (! Visited [I]) {DFS (I) ;}} memset (visited, 0, sizeof (visited); for (I = n-1; I> = 0; I --) {If (! Visited [num [I]) DFS (Num [I], num [I]) ;}} void _ test () {Init (); puts ("strongly connected components of each vertex:"); For (INT I = 0; I <CNT; I ++) {printf ("% d ", STC [I]);} puts ("") ;}int main () {__ test ();} /* 9 80 11 21 42 70 33 60 84 70 10 32 02 12 33 03 2 */