problem:https://www.spoj.com/problems/SUBMERGE/
my code
#include<bits/stdc++.h>
#include
using namespace std;
const int p=31;
const int m=1e9+9;
typedef long long ll;
vector vis;
vector dis;
vector low;
int t=0;
int ct=0;
set s;
void art(int v,vectoradj[10000],int p=-1){
vis[v]=true;
dis[v]=low[v]=t++;
int children=0;
for(int x:adj[v]){
if(x==p) continue;
if(vis[x]) low[v]=min(low[v],dis[x]);
if(!vis[x]){
children++;
art(x,adj,v);
low[v]=min(low[v],low[x]);
if(low[x]>=dis[v]&&p!=-1)
s.insert(v);
}
}
if(p==-1 && children>1)
s.insert(v);
}
int main (){
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
while(true){
int N,M,x,y;
cin>>N>>M;
if(M==0||N==0) return(0);
std::vector<int> adj[10002];
dis.assign(N,-1);
low.assign(N,-1);
vis.assign(N,false);
for(int i=0;i<M;i++){
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
art(1,adj);
int n;
n=s.size();
s.clear();
cout<<n<<"\n";
ct=0;
t=0;
}
}