割點和橋模板

2021-07-23 15:47:16 字數 1212 閱讀 8323

#include#include #include #include using namespace std;  

#define mymax 200

typedef vectoredge;

vectorg(mymax);

bool visited[mymax] ;

int dfn[mymax] ;

int low[mymax] ;

int father[mymax]; //dfs樹中每個點的父節點

bool biscutvetext[mymax]; //每個點是不是割點

int ntime; //dfs時間戳

int n,m; //n是點數,m是邊數

void tarjan(int u, int father) //father 是u的父節點

else if( father != v ) // 連到父節點的回邊不考慮, 否則求不出橋

low[u] = min(low[u],dfn[v]);

} }void count()

} if( nrootsons > 1)

biscutvetext[1] = true;

for( i = 1;i <= n;i ++ )

if( biscutvetext[i] )

cout << i << endl;

for( i = 1;i <= n;i ++)

memset( dfn,0,sizeof(dfn));

memset( father,0,sizeof(father));

memset( biscutvetext,0,sizeof(biscutvetext));

count();

return 0;

}

input: (11點13邊)  

11 13

1 2

1 4

1 5

1 6

2 11

2 3

4 3

4 9

5 8

5 7

6 7

7 10

11 3  

output:

1  4

5 7

5,8

4,9

7,10

強連通割點割橋模板

如果u是根節點,只要它有兩個子節點就說明是割點,否則,滿足 u,v 為樹枝邊 或稱父子邊,即u是v的父親 使得dfn u low v 橋無向邊 u,v 當且僅當 u,v 為樹枝邊,且滿足dfn u include include include include include include inc...

tarjan雙聯通求割點和橋模板

詳見 求割點 int n,m,stamp,low 1005 dfn 1005 iscut 1005 iscut記錄的為割點 vector vec 1005 void tarjan int index,int fa else if dfn tmp fa if fa 0 child 1 iscut in...

割邊(橋 模板

用tarjan求橋並輸出 include include include include using namespace std const int maxn 10010 int n,m,x,y,index dfn maxn low maxn ans,a index 代表當前的時間戳 vectorg...