概念
基环树就是有n个点n条边的图(比树多出现一个环)。
特殊形态的基环树
无向树(N点N边无向图)
外向树(每个点只有一条入边)
内向树(每个点只有一条出边)
以上三种树有十分优秀的性质,就是可以直接将环作为根。就可以对每个环的子树进行单独处理,最后再处理环
找环
- 无向图
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5010;
struct Edge{
int v,nxt;}edge[N<<1];
struct Line{
int u,v;}line[N<<1];
int n,m,cnt,head[N],dfn[N],ind,fa[N],loop[N],len;
bool ban[N][N];
int t,ans[N],rec[N];
bool cmp(Line a,Line b){
return a.v>b.v;}
void addedge(int u,int v){
edge[++cnt].v=v;edge[cnt].nxt=head[u];head[u]=cnt;
}
void getloop(int u){
dfn[u]=++ind;
for(int i=head[u];i;i=edge[i].nxt){
int v=edge[i].v;
if(v==fa[u]) continue;
if(dfn[v]){
if(dfn[v]<dfn[u]) continue;
for</