显示代码纯文本
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
#define Clear(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x3fffffff;
//==============struct declaration=============
struct adj{
int to,no;
adj(int to=0,int no=0):to(to),no(no){}
};
//==============var declaration=================
const int MAXN=5010;
int n,m,Index=0;
vector <adj> Edge[MAXN];
int pre[MAXN],low[MAXN],deg[MAXN];
//==============function declaration============
void tarjan(int x,int pa);
//==============main code=======================
int main()
{
#define FILE__
#ifdef FILE__
freopen("rpathsa.in","r",stdin);
freopen("rpathsa.out","w",stdout);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int s,e;
scanf("%d%d",&s,&e);
Edge[s].push_back(adj(e,i));
Edge[e].push_back(adj(s,i));
}
memset(pre,0,sizeof(pre));memset(deg,0,sizeof(deg));
tarjan(1,-1);
for(int x=1;x<=n;x++){
int siz=Edge[x].size();
for(int i=0;i<siz;i++){
int &e=Edge[x][i].to;
if (low[e]==low[x]) continue;
deg[low[e]]++;
}
}
int ans=0;
for(int i=1;i<=n;i++){
if (deg[i]==1)
ans++;
}
printf("%d\n",(ans+1)/2);
return 0;
}
//================fuction code====================
void tarjan(int x,int pa)
{
pre[x]=low[x]=++Index;
int siz=Edge[x].size();
for(int i=0;i<siz;i++){
adj &e=Edge[x][i];
if (e.no==pa) continue;
if (pre[e.to]!=0)
low[x]=min(low[x],pre[e.to]);
else{
tarjan(e.to,e.no);
low[x]=min(low[x],low[e.to]);
}
}
}