# Light OJ 1063 – Ant Hills

Problem Link : http://www.lightoj.com/volume_showproblem.php?problem=1063

```
/*
+-+ +-+ +-+
|R| |.| |S|
+-+ +-+ +-+
*/

#include &lt;bits/stdc++.h&gt;

#define pii             pair &lt;int,int&gt;
#define sc              scanf
#define pf              printf
#define Pi              2*acos(0.0)
#define ms(a,b)         memset(a, b, sizeof(a))
#define pb(a)           push_back(a)
#define MP              make_pair
#define db              double
#define ll              long long
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define D(x)            cout&lt;&lt;#x &quot; = &quot;&lt;&lt;(x)&lt;&lt;endl
#define VI              vector &lt;int&gt;
#define DBG             pf(&quot;Hi\n&quot;)
#define MOD             100007
#define MAX             100007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0)
#define SZ(a)           (int)a.size()
#define sf(a)           scanf(&quot;%d&quot;,&amp;a)
#define sff(a,b)        scanf(&quot;%d%d&quot;,&amp;a,&amp;b)
#define sfff(a,b,c)     scanf(&quot;%d%d%d&quot;,&amp;a,&amp;b,&amp;c)
#define loop(i,n)       for(int i=0;i&lt;n;i++)
#define REP(i,a,b)      for(int i=a;i&lt;b;i++)
#define TEST_CASE(t)    for(int z=1;z&lt;=t;z++)
#define PRINT_CASE      printf(&quot;Case %d: &quot;,z)
#define all(a)          a.begin(),a.end()
#define intlim          2147483648
#define inf             1000000
#define ull             unsigned long long

using namespace std;

vector&lt;int&gt;graph[MAX];
int n,m,cnt;
bool visited[MAX],artpoint[MAX];
int back_edge[MAX],dis[MAX],degroot,dfsnum,root;

void dfs(int u)
{
visited[u]=1;
dfsnum++;
back_edge[u]=dis[u]=dfsnum;
loop(i,SZ(graph[u]))
{
int v=graph[u][i];
if(!visited[v])
{
dfs(v);
if(u==root) degroot++;
if(degroot&gt;=2)
{
artpoint[root]=1;
}

back_edge[u]=min(back_edge[u],back_edge[v]);
if(back_edge[v]&gt;=dis[u] &amp;&amp; u!=root)
{
artpoint[u]=1;
}

}
else
back_edge[u]=min(back_edge[u],dis[v]);
}
}

void allclear()
{
loop(i,n+5)
{
graph[i].clear();
visited[i]=0;
artpoint[i]=0;
back_edge[i]=0;
dis[i]=0;
}
cnt=dfsnum=degroot=0;
}

int main()
{
///freopen(&quot;in.txt&quot;,&quot;r&quot;,stdin);
///freopen(&quot;out.txt&quot;,&quot;w&quot;,stdout);
int t;
sf(t);
TEST_CASE(t)
{
sff(n,m);
allclear();
int a,b;
loop(i,m)
{
sff(a,b);
graph[a].pb(b);
graph[b].pb(a);
}

root=1;
dfs(1);

REP(i,1,n+1)
if(artpoint[i]) cnt++;
PRINT_CASE;
cout&lt;&lt;cnt&lt;&lt;endl;
}
return 0;
}

```
Article Rating
Subscribe
Notify of