CF723E.One-Way Reform
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads.
The road minister decided to make a reform in Berland and to orient all roads in the country, i.e. to make each road one-way. The minister wants to maximize the number of cities, for which the number of roads that begins in the city equals to the number of roads that ends in it.
伯兰德有 n 座城市和 m 条双向道路,每条道路连接两座城市。已知任意两座城市之间至多只有一条道路相连,且不存在连接某座城市与其自身的道路。仅通过这些道路,可能无法从某座城市到达另一座城市。
道路部长决定对伯兰德进行改革,将全国所有道路定向,即把每条道路改为单向道路。部长希望最大化满足“以该城市为起点的道路数等于以该城市为终点的道路数”的城市的数量。
输入格式
The first line contains a positive integer t (1 ≤ t ≤ 200) — the number of testsets in the input.
Each of the testsets is given in the following way. The first line contains two integers n and m (1 ≤ n ≤ 200, 0 ≤ m ≤ n·(n - 1) / 2) — the number of cities and the number of roads in Berland.
The next m lines contain the description of roads in Berland. Each line contains two integers u and v (1 ≤ u, v ≤ n) — the cities the corresponding road connects. It's guaranteed that there are no self-loops and multiple roads. It is possible that there is no way along roads between a pair of cities.
It is guaranteed that the total number of cities in all testset of input data doesn't exceed 200.
Pay attention that for hacks, you can only use tests consisting of one testset, so t should be equal to one.
第一行包含一个正整数 t(1≤t≤200)—— 输入中测试集的数量。
每个测试集按如下方式给出:第一行包含两个整数 n 和 m(1≤n≤200,0≤m≤n⋅(n−1)/2)—— 分别表示 Berland 的城市数量和道路数量。
接下来的 m 行描述 Berland 的道路。每行包含两个整数 u 和 v(1≤u,v≤n)—— 表示该道路所连接的两座城市。保证不存在自环和重边。可能存在某些城市对之间无法通过道路互相到达。
保证输入数据中所有测试集的城市总数不超过 200。
注意:对于 hack 测试,你只能使用仅含一个测试集的测试用例,因此 t 必须等于 1。
输出格式
For each testset print the maximum number of such cities that the number of roads that begins in the city, is equal to the number of roads that ends in it.
In the next m lines print oriented roads. First print the number of the city where the road begins and then the number of the city where the road ends. If there are several answers, print any of them. It is allowed to print roads in each test in arbitrary order. Each road should be printed exactly once.
对于每个测试用例,输出满足“以该城市为起点的路的数量等于以该城市为终点的路的数量”的城市最多有多少个。
接下来的 m 行中,输出有向边(道路)。每行先输出道路起点所在城市的编号,再输出道路终点所在城市的编号。若存在多个合法答案,输出任意一个即可。允许在每个测试用例中以任意顺序输出各条道路。每条道路必须且仅能输出一次。
输入输出样例
输入#1
2 5 5 2 1 4 5 2 3 1 3 3 5 7 2 3 7 4 2
输出#1
3 1 3 3 5 5 4 3 2 2 1 3 2 4 3 7
输入解题思路,AI测评打分。不知道怎么写?