Problem Link -> https://www.hackerearth.com/practice/algorithms/graphs/biconnected-components/tutorial/
Go to the bottom of the page for the problem. Is the visible test case for the problem correct?
My Code
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define setprec(ans) cout<<fixed<<std::setprecision(9)<<ans<<endl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long int ll;
ll find_combinations(VI &cycles){
ll ans=0;
for(auto x: cycles){
ans = (ans + ((ll)x*(x-1)))%MOD;
}
return ans;
}
void dfs_1(int x, int &c, VVI &graph, VI &in, VI &out, VI &parent){
in[x] = ++c;
for(auto child: graph[x]){
if(in[child] == INT_MAX){
//this vertex is not visited yet
parent[child] = x;
dfs_1(child, c, graph, in, out, parent);
if(out[child] <= in[x]){
out[x] = min(out[x], out[child]);
}
}
else{
//visited, can be a parent or ancestor
if(parent[x] != child){
//ancestor
out[x] = min(out[x], in[child]);
}
}
}
}
int dfs_2(int x, VVI &graph, VI &in, VI &out, VI &vis){
vis[x] = 1;
int c = 1;
for(auto child: graph[x]){
if(!vis[child] && in[child] >= out[child]) c += dfs_2(child, graph, in, out, vis);
}
return c;
}
void solve(){
int n, m;cin>>n>>m;
VVI graph(n);
for(int i=0;i<m;i++){
int u, v;cin>>u>>v;
//u--, v--;
graph[u].push_back(v);
graph[v].push_back(u);
}
VI in(n, INT_MAX), out(n, INT_MAX), parent(n, -1);
int c=0;
for(int i=0;i<n;i++){
if(in[i] == INT_MAX){
dfs_1(i, c, graph, in, out, parent);
}
}
VI cycles;
int odd_count = 0, even_count = 0;
VI vis(n, 0);
for(int i=0;i<n;i++){
if(in[i] >= out[i] && (vis[i] == 0)){
int temp = dfs_2(i, graph, in, out, vis);
if(temp%2 == 1) odd_count++;
else even_count++;
}
}
cout<<odd_count<<" "<<even_count;
//cout<<find_combinations(cycles);
}
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
int t;t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}