Lightoj 1063 Ant Hills

Source: Internet
Author: User

Ant hillstime limit:2000msmemory limit:32768kbthis problem'll be judged onLightoj. Original id:1063
64-bit integer IO format: %lld Java class name: Main

After many years of peace, an Ant-war have broken out.

In the days leading the outbreak of war, the ant government devoted a great deal of resources toward gathering Intel Ligence on Ant Hills. It discovered the following:

    1. The Ant Empire has a large network of ant-hills connected by bidirectional tracks.
    2. It is possible to send a message from any Ant hill to any other Ant hill.

Now your want to stop the war. Since They sometimes attack your house and disturb your quite a lot. So, you have made a plan. You have a gun which can destroy exactly one ant-hill. So, the want to hits an ant hill if it can stop at least the other ant hills passing messages between them. Now your want the total number of Ant hills your may choose to fire.

Input

Input starts with an integer T (≤20), denoting the number of test cases.

Each test case contains a blank line and integers n (1≤n≤10000), M (1≤m≤20000). n denotes the number of Ant Hills and m denotes the number of bi-directional tracks. Each of the next m lines would contain the different integers a B (1≤a, b≤n) denoting that there is a Track between a and b.

Output

For each case, print the case number and the total number of your ant hills choose to fire.

Sample Input

2

5 4

2 1

1 3

5 4

4 1

3 3

1 2

2 3

1 3

Sample Output

Case 1:2

Case 2:0

Source

Problem Setter:jane Alam Jan solution: Cut points
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =10010;4 structArc {5     intTo,next;6Arcintx =0,inty =-1) {7to =x;8Next =y;9     }Ten} e[100000]; One intHEAD[MAXN],DFN[MAXN],LOW[MAXN]; A inttot,idx,ans,n,m; - BOOLVIS[MAXN]; - voidAddintUintv) { theE[tot] =arc (V,head[u]); -Head[u] = tot++; -E[tot] =arc (U,head[v]); -HEAD[V] = tot++; + } - voidTarjan (intUintFA) { +Dfn[u] = Low[u] = + +idx; A     intson =0; at      for(inti = Head[u]; ~i; i =E[i].next) { -         if(!Dfn[e[i].to]) { - Tarjan (e[i].to,u); -Low[u] =min (low[u],low[e[i].to]); -son++; -             if(!vis[u]&& (FA = =-1&& son >1|| FA! =-1&& Low[e[i].to] >=Dfn[u])) { inVis[u] =true; -ans++; to             } +}ElseLow[u] =min (low[u],dfn[e[i].to]); -     } the } * intMain () { $     intT,u,v,cs =1;Panax Notoginsengscanf"%d",&T); -      while(t--) { thescanf"%d%d",&n,&m); +memset (head,-1,sizeof(head)); Amemset (DFN,0,sizeof(DFN)); thememset (Low,0,sizeof(Low)); +memset (Vis,false,sizeof(Vis)); -Ans = tot =0; $          for(inti =0; I < m; ++i) { $scanf"%d%d",&u,&v); - Add (u,v); -         } theTarjan (1,-1); -printf"Case %d:%d\n", cs++, ans);Wuyi     } the     return 0; -}
View Code

Lightoj 1063 Ant Hills

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.