CF25D.Roads not only in Berland
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones.
贝尔兰政府决定改善与邻国的关系。首先,政府决定修建新道路,使得贝尔兰及其邻国的所有城市之间均能相互连通。目前,贝尔兰及其邻国一共有 n 座城市,且恰好有 n−1 条双向道路。由于最近的金融危机,贝尔兰政府面临严重的资金压力,因此每修建一条新道路,就必须关闭一条已有的道路。每天最多可以关闭一条现有道路,并立即修建一条新道路。你的任务是:确定为使所有城市彼此连通所需最少的天数,并给出旧道路关闭与新道路修建的具体方案。
输入格式
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers a__i, b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself.
第一行包含一个整数 n(2≤n≤1000)—— 表示 Berland 及其邻国的城市总数。接下来的 n−1 行描述了道路。每条道路由两个以空格分隔的整数 ai、bi(1≤ai,bi≤n,且 ai=bi)描述,表示该道路所连接的两个城市。任意两个城市之间至多只有一条道路。不存在连接城市自身的道路。
输出格式
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any.
输出答案,即数字 t —— 重建道路所需的最少天数,使得从任意城市出发均可到达其余所有城市。然后输出 t 行,表示关闭旧道路并修建新道路的计划。每行描述一天的操作,格式为 i j u v,表示城市 i 与城市 j 之间的道路被关闭,同时在城市 u 与城市 v 之间新建一条道路。城市编号从 1 开始。若答案不唯一,输出任意一个即可。
输入输出样例
输入#1
2 1 2
输出#1
0
输入#2
7 1 2 2 3 3 1 4 5 5 6 6 7
输出#2
1 3 1 3 7
输入解题思路,AI测评打分。不知道怎么写?