Sicily 14181. Flying Safely

14181. Flying Safely

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Due to budget cuts, even spies have to use commercial airlines nowadays to travel between cities in the world. Although this mode of travel can be very convenient for a spy, it also raises a problem: the spy has to trust the pilot to make sure he is not in
danger during the flight. And even worse, sometimes there is no direct flight between some pairs of cities, so that the spy has to take multiple flights to get to the desired location, and thus has to trust multiple pilots!

To limit the trust issues you are asked for help. Given the flight schedule, figure out the smallest set of pilots that need to be trusted, such that the spy can safely travel between all cities.

Input

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with two space-separated integers n (2 ≤ n ≤ 1 000) and m (1 ≤ m ≤ 10 000): the number of cities and the number of pilots, respectively. 
  • m lines with two space-separated integers a and b (1 ≤ a, b ≤ n, a ≠ b): a pilot flying his plane back and forth between city a and b.

It is possible to go from any city to any other city using one or more flights. In other words: the graph is connected.

Output

Per test case:

  • one line with and integer: the minimum number of pilots that need to be trusted such that it is possible to travel between each pair of cities.

Sample Input

2
3 3
1 2
2 3
1 3
5 4
2 1
2 3
4 3
4 5

Sample Output

2
4

Problem Source

2015年每周一赛第七场

// Problem#: 14181
// Submission#: 3705500
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>

int main() {
    int c;
    char C[30];
    scanf("%d\n", &c);
    while (c--) {
        int n, m;
        scanf("%d%d\n", &n, &m);
        printf("%d\n", n - 1);
        while (m--) gets(C);
    }
    return 0;
}                                 
时间: 2024-10-11 13:11:55

Sicily 14181. Flying Safely的相关文章

sicily 1063. Who&#39;s the Boss

Time Limit: 1sec    Memory Limit:32MB Description Several surveys indicate that the taller you are, the higher you can climb the corporate ladder. At TALL Enterprises Inc. this "de facto standard" has been properly formalized: your boss is alway

hdu1800 Flying to the Mars(字典树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14340    Accepted Submission(s): 4572 Problem Description In the year 8888

让Flying saucer支持font定义

在wangEditor里给某段字体加上颜色后,在生成的PDF里无法体现出来,只好打开flying saucer的源码debug,发现XhtmlNamespaceHandler类中没有对font元素的处理,于是依样画瓢: public String getNonCssStyling(Element e) { if (e.getNodeName().equals("table")) { return applyTableStyles(e); } else if (e.getNodeName

about building flying sauser

download flying sauser: unzip flyingsaucer-master.zip cd flyingsaucer-master/ mvn install ls -al cd flying-saucer-core/ cd target/ ls -al pwd so you can get the jar package that you need when you program

Sicily 1146:Lenny&#39;s Lucky Lotto(dp)

题意:给出N,M,问有多少个长度为N的整数序列,满足所有数都在[1,M]内,并且每一个数至少是前一个数的两倍.例如给出N=4, M=10, 则有4个长度为4的整数序列满足条件: [1, 2, 4, 8], [1, 2, 4, 9], [1, 2, 4, 10], [1, 2, 5, 10] 分析:可用动态规划解题,假设dp[i][j],代表满足以整数i为尾数,长度为j的序列的个数(其中每一个数至少是前一个数的两倍).那么对于整数i,dp[i][j] 等于所有dp[k][j-1]的和,其中k满足:

HDU 5515 Game of Flying Circus 二分

Game of Flying Circus Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5515 Description The discovery of anti-gravitations technology changed the world. The invention of anti-gravitation shoes (Grav-shoes) enable

LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1341 Description It's said that Aladdin had to solve seven

UVA 11280 - Flying to Fredericton(最短路)

UVA 11280 - Flying to Fredericton 题目链接 题意:给定一些国家,和两个国家间的花费,现在有一些询问,询问每次最多转k次飞机,最小花费 思路:dijkstra变形,多开一维表示转机次数即可 代码: #include <cstdio> #include <cstring> #include <vector> #include <queue> #include <iostream> #include <strin

hdu---(1800)Flying to the Mars(trie树)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11228    Accepted Submission(s): 3619 Problem Description In the year 8888, the Earth is ruled by the PPF Empire . As the popul