【Loj #10102. 「一本通 3.6 练习 3」旅游航道】题解
题目链接
题目中对主要航道定义是这样的:
如果某一条航道的删除使得一些星球不能到达,那么这条航道是不能删除的,称之为「主要航道」。
这说明了什么?
说明了主要航道就是桥。
然后题目就是求桥的个数。
模板题。
Code
// Problem: #10102. 「一本通 3.6 练习 3」旅游航道
// Contest: LibreOJ
// URL: https://loj.ac/p/10102
// Memory Limit: 512 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define M
//#define mo
#define N 30010
struct node
{
int x, y, n;
}d[N*2];
int n, m, i, j, k;
int f[N], dep[N], h[N], c[N*2];
int u, v, ans;
int fa(int x)
{
if(f[x]==x) return x;
return f[x]=fa(f[x]);
}
void cun(int x, int y)
{
d[++k].x=x; d[k].y=y;
d[k].n=h[x]; h[x]=k;
}
void dfs(int x)
{
for(int g=h[x]; g; g=d[g].n)
{
if(c[g]) continue;
c[g]=c[((g-1)^1)+1]=1;
int y=d[g].y;
if(!dep[y])
{
dep[y]=dep[x]+1;
dfs(y);
}
if(dep[fa(y)]>=0)
{
if(dep[f[y]]