CF87D.Beautiful Road

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A long time ago in some country in Asia were civil wars.

Each of n cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city.

Road making was difficult, so the country had few roads, exactly n - 1. Also you could reach any city from any other city going on those roads.

Even during the war the Oriental people remain spiritually rich and appreciate the beauty of nature. And to keep the memory of this great crusade for the centuries to come, they planted one beautiful tree by the road on which the army spent most time. The Oriental people love nature, that's why if there were several such roads, then one tree was planted by each of them.

Recently, when the records of the war were found, it became clear that each city attacked each other one exactly once. There were exactly n(n - 1) attacks in total. Everyone has been wondering what road after those wars became the most beautiful, that is, by which road they planted the largest number of beautiful trees.

很久以前,在亚洲某个国家爆发了内战。

共有 nn 座城市,每座城市都想夺取政权。因此,有时某座城市会集结军队,派兵远征另一座城市。

修路十分困难,因此全国道路稀少,恰好只有 n−1n-1 条;并且任意两座城市之间均可通过这些道路相互抵达。

即便在战争期间,东方人依然精神富足,热爱自然之美。为了将这场伟大远征的壮丽记忆永世留存,他们在军队行军耗时最长的那条道路上种下一棵美丽的树。由于东方人热爱自然,因此若存在多条耗时相同的最长道路,则每条这样的道路上都会种下一棵树。

最近,当战争记录被发掘出来后,人们发现:每座城市都曾恰好向其余每座城市发动过一次进攻,总计发生了 n(n−1)n(n-1) 次进攻。人们一直好奇:经过这些战争之后,哪条道路变得最为美丽——即哪条道路上所种植的美丽树木数量最多?

输入格式

The first line contains an integer n (2 ≤ n ≤ 105), which represents the number of cities. Next n - 1 lines contain three integers each: the numbers of cities a__i, b__i (1 ≤ a__i, b__i ≤ n), connected by the i-th road and the number of days d__i the army spends to go on it (1 ≤ d__i ≤ 109). The lengths of several roads may coincide.

第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^5),表示城市的数量。接下来的 n−1n-1 行每行包含三个整数:由第 ii 条道路连接的两座城市编号 aia_i、bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n)以及军队通过该道路所需天数 did_i(1≤di≤1091 \leq d_i \leq 10^9)。多条道路的长度可能相同。

输出格式

Print on the first line two integers — the number of beautiful trees on the most beautiful road and the number of the most beautiful roads. Print on the second line the list of the most beautiful roads in the sorted order by the numbers' increasing. The roads are numbered from 1 to n - 1 in the order in which they are given in the input data.

Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).

第一行输出两个整数:最美丽道路上的美丽树的数量,以及最美丽道路的数量。
第二行按编号升序输出所有最美丽道路的编号列表(即从小到大排序)。道路编号从 1 到 n−1n-1,按照输入数据中给出的顺序依次编号。

请注意,在 C++ 中不要使用 %lld 格式说明符来输出 64 位整数。推荐使用 cout 流(也可使用 %I64d 格式说明符)。

输入输出样例

  • 输入#1

    2
    2 1 5

    输出#1

    2 1
    1
  • 输入#2

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

    输出#2

    16 1
    2

输入解题思路,AI测评打分。不知道怎么写?

首页