你谷最菜
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL maxn = 5e5 + 5;
int n, m, u, v, cnt, dfn[maxn], low[maxn];
vector <pair <int, int> > e[maxn];
vector <vector <int> > ans;
stack <int> st;
void tarjan(int x, int las)
{
low[x] = dfn[x] = ++cnt;
st.push(x);
for(auto i: e[x])
{
if(i.second == (las ^ 1)) continue;
if(!dfn[i.first])
{
tarjan(i.first, i.second);
low[x] = min(low[x], low[i.first]);
}
else
low[x] = min(low[x], dfn[i.first]);
}
if(dfn[x] == low[x])
{
vector <int> vec;
vec.push_back(x);
while(st.top() != x)
{
vec.push_back(st.top());
st.pop();
}
st.pop();
ans.push_back(vec);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
cin >> u >> v;
e[u].push_back(make_pair(v, i * 2));
e[v].push_back(make_pair(u, i * 2 + 1));
}
for(int i = 1; i <= n; i++)
if(!dfn[i])
tarjan(i, 0);
cout << ans.size() << '\n';
return 0;
}