LightOJ 1063 Ant Hills

Ant Hills

Time Limit: 2000ms

Memory Limit: 32768KB

This problem will be judged on LightOJ. Original ID: 1063
64-bit integer IO format: %lld      Java class name: Main

After many years of peace, an ant-war has broken out.

In the days leading up to the outbreak of war, the ant government devoted a great deal of resources toward gathering intelligence 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 you want to stop the war. Since they sometimes attack your house and disturb you quite a lot. So, you have made a plan. You have a gun which can destroy exactly one ant-hill. So, you want to hit an ant hill if it can stop at least two other ant hills passing messages between them. Now you want the total number of ant hills you 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 two 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 will contain two 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 ant hills you may 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

解题:求割点数

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 10010;
 4 struct arc {
 5     int to,next;
 6     arc(int x = 0,int y = -1) {
 7         to = x;
 8         next = y;
 9     }
10 } e[100000];
11 int head[maxn],dfn[maxn],low[maxn];
12 int tot,idx,ans,n,m;
13 bool vis[maxn];
14 void add(int u,int v) {
15     e[tot] = arc(v,head[u]);
16     head[u] = tot++;
17     e[tot] = arc(u,head[v]);
18     head[v] = tot++;
19 }
20 void tarjan(int u,int fa) {
21     dfn[u] = low[u] = ++idx;
22     int son = 0;
23     for(int i = head[u]; ~i; i = e[i].next) {
24         if(!dfn[e[i].to]) {
25             tarjan(e[i].to,u);
26             low[u] = min(low[u],low[e[i].to]);
27             son++;
28             if(!vis[u]&&(fa == -1 && son > 1 || fa != -1 && low[e[i].to] >= dfn[u])) {
29                 vis[u] = true;
30                 ans++;
31             }
32         } else low[u] = min(low[u],dfn[e[i].to]);
33     }
34 }
35 int main() {
36     int T,u,v,cs = 1;
37     scanf("%d",&T);
38     while(T--) {
39         scanf("%d %d",&n,&m);
40         memset(head,-1,sizeof(head));
41         memset(dfn,0,sizeof(dfn));
42         memset(low,0,sizeof(low));
43         memset(vis,false,sizeof(vis));
44         ans = tot = 0;
45         for(int i = 0; i < m; ++i) {
46             scanf("%d %d",&u,&v);
47             add(u,v);
48         }
49         tarjan(1,-1);
50         printf("Case %d: %d\n",cs++,ans);
51     }
52     return 0;
53 }

时间: 2024-08-30 16:36:52

LightOJ 1063 Ant Hills的相关文章

【lightoj-1063】Ant Hills(求割点)

求割点模板题 #include <bits/stdc++.h> using namespace std; const int N = 10004; int dfn[N], low[N]; bool ok[N]; vector<int>V[N]; int n, num, root; void dfs(int s, int f) { low[s] = dfn[s] = ++num; int child = 0; for(unsigned int i = 0; i < V[s].s

jmeter+ant+jenkins+mac报告优化

一.在上篇博客中生成的报告有两个问题: 1.date not defined 2.Min Time和Max Time显示成了NaN 二.Jmeter+Ant报告生成原理: 在解决问题之前,让我们先弄清楚Jmeter+Ant是生成报告的原理,知道原理后我们就可以很从容的解决问题了.另外,如果后续我们想定制报告也就很容易了. 1.在Jmeter的extras目录下,官方已经为我们提供了一个现成的实例,我们只需要在该目录下执行ant命令就可以生成一个数据文件Test.jtl和一个报告Test.html

Ant: Class not found: javac1.8

今天用ant,在选择build.xml,run as ant build后出错Ant: Class not found: javac1.8 分析问题:是否是eclipse中的ant版本和java的版本不匹配那? 解决方法如下: 1. 去下载一个最新版本的ant,解压到本地相应目录下,我下载的是apache-ant-1.9.7 2. 在eclipse中, windows-  references---Ant  ----run time,点击Ant home, 将路径制定到下载的ant目录下 3.

Maven和Ant的区别

最近做的项目中一直是在使用maven,但是要知道最早出来的构建工具是Ant,现在Ant依然有好多人再用,于是自己就抽出来时间,学习了一下Ant的基本的使用.这样也能跟好的理解Maven提供的新特性. 首先说一下他们各自的作用: Ant的作用:是一种基于Java的build工具 可以用ant编译java类,生成class文件 ant可以自定义标签.配置文件,用于构建. ant可以把相关层构建成jar包 . ant把整个项目生成web包,并发布到Tomcat Ant的优点: 跨平台性:Ant是纯Ja

LightOJ 1030 Discovering Gold【概率】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题意:基础概率题. 代码: #include <stdio.h> #include <string.h> #include <vector> #include <string> #include <algorithm> #include <iostream> #include <iterator>

Ant入门教程之部署Java项目

Ant可以代替使用javac.java和jar等命令来执行java操作,从而达到轻松的构建和部署Java工程的目的. 1.利用ant的javac命令来编译Java程序 Ant的javac命令用于实现编译Java程序的功能.下面来看一个简单的例子:首先我们建立名为 JavaPro的Java项目, 建立src目录为源代码目录,在src目录下建立TestAnt.java这个类文件.该类文件的内容如下: package com.home; public class TestAnt{ public sta

ant编译后用hadoop报Could not find or load main class

错误信息: [[email protected] HDFS_Java_API]$ hadoop HDFSJavaAPI.jar HDFSJavaAPIDemo Warning: $HADOOP_HOME is deprecated. Error: Could not find or load main class HDFSJavaAPI.jar 报错原因: 当前运行的 .class  文件不在 hadoop-env.sh文件中 解决办法: 在 hadoop-env.sh中配置HADOOP_CLA

ant完成文件上传和启动服务

首先,请先下载JAR包.Ant上传文件到Linux服务器使用scp,需要下载jar包jsch.jar,将jar包放入ant的lib文件夹下. <?xml version="1.0" ?> <project name="${project.name}" default="start-server" basedir="."> <property name="password" va

LightOJ - 1370 Bi-shoe and Phi-shoe

题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题目大意:给N个数a[i], N <= 1e6,问使 Φ(x) >= a[i] 成立的最小x的所有x的和是多少. 解题思路:我们知道的是对于素数 m 来说,phi[m] = m - 1.另一方面,对于一个合数 m 来说, phi[m] < phi[x] , x > m && x 是素数. 因此,我们可以认为,每