其中:1595446(節點個數)
0(起始邊) 1(終邊)
base.h
#pragma once
#include "tree.h"
class
cbase
;
base.cpp
#include "stdafx.h"
#include "base.h"
cbase::cbase(ctree *t, int l)
cbase::~cbase()
tree.h
#pragma once
#include "treenode.h"
class ctree
;
treenode.cpp
#pragma once
class ctreenode
;
kasaraju.h
#pragma once
#include "base.h"
#include "ftime.h"
#include
class
ckasaraju : public
cbase
;
kasaraju.cpp
#include "stdafx.h"
#include "kasaraju.h"
#include "base.h"
#include
#include
#include
using namespace std;
ckasaraju::ckasaraju(ctree *t, int l):cbase(t, l)
ckasaraju::~ckasaraju()
void ckasaraju::getresult()
/*2、g為tree的轉置*/
g = reverse();
/*3、找出所有的強連通分量*/
int ij = 0;
for (int i = count; i >= 0; i--) //g圖的深度優先
cout << "共"
<< ij << "組強連通分量";
}void ckasaraju::g_dfsvisit(ctree*tnode)
p = p->next;
}}void ckasaraju::dfsvisit(ctree*tnode)
p = p->next;
}tnode->state = 2;
finish[count++] = tnode->value;
}ctree * ckasaraju::reverse()
for (int i = 0; i < length; i++)
}deletetree;
return g;
}
main函式
//#include "stdafx.h"
#include "tree.h"
#include "kasaraju.h"
#include "time.h"
#include
#include
#include
#include
#include "tarjan.h"
using
namespace
std;
ctree* createtree(char* filename,int &length)
ctreenode *nt;
while(!readfile.eof()) //按空格讀取,遇到空白符結束
return tree;
}int main()
強連通分量 tarjan求強連通分量
雙dfs方法就是正dfs掃一遍,然後將邊反向dfs掃一遍。挑戰程式設計 上有說明。雙dfs 1 include 2 include 3 include 4 include 5 6using namespace std 7const int maxn 1e4 5 8 vector g maxn 圖的鄰...
強連通分量
對於有向圖的乙個頂點集,如果從這個頂點集的任何一點出發都可以到達該頂點集的其餘各個頂點,那麼該頂點集稱為該有向圖的乙個強連通分量。有向連通圖的全部頂點組成乙個強連通分量。我們可以利用tarjan演算法求強連通分量。define n 1000 struct edge e 100000 int ec,p...
強連通分量
在有向圖g中,如果兩個頂點間至少存在一條路徑,稱兩個頂點強連通 strongly connected 如果有向圖g的每兩個頂點都強連通,稱g是乙個強連通圖。非強連通圖有向圖的極大強連通子圖,稱為強連通分量 strongly connected components 下圖中,子圖為乙個強連通分量,因為...