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;
}                                 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值