| 比赛 | 
    4043级NOIP2022欢乐赛7th | 
    评测结果 | 
    AAAAAAAAAAAAAAAAA | 
    | 题目名称 | 
    冗余路径(Redundant Paths) | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    ZRQ | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2022-11-20 09:01:58 | 
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=10005,M=50005;
int n,m,ans,siz,tot;
int hd[N],nt[M],e[M],idx=1;
int df[N],lw[N],clk,in[N],dc[N],dcc;
int st[N],top; 
bool cut[M],vis[N]; 
inline void add(int x,int y)
{
	nt[++idx]=hd[x],hd[x]=idx,e[idx]=y;
}
void tarjan(int cur,int in)
{
	df[cur]=lw[cur]=++clk;
	st[++top]=cur;
	for(int i=hd[cur];i;i=nt[i])
		if(!df[e[i]])
		{
			tarjan(e[i],i);
			lw[cur]=min(lw[cur],lw[e[i]]);
			if(lw[e[i]]>df[cur]) cut[i]=cut[i^1]=1;
		}
		else if(i!=(in^1)) lw[cur]=min(lw[cur],df[e[i]]);
	if(df[cur]==lw[cur])
	{
		++dcc;
		int x;
		do
		{
			x=st[top--];
			dc[x]=dcc;
		}while(x!=cur);
	}
	return ;
}
int main()
{
	freopen("rpaths.in","r",stdin);
	freopen("rpaths.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=m;++i) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	tarjan(1,0);
	for(int i=2;i<=idx;++i)
		if(cut[i])
			++in[dc[e[i]]];
	for(int i=1;i<=dcc;++i)
		if(in[i]==1)
			++ans;
	printf("%d\n",(ans+1)>>1); 
	return 0;
}