CF666B.World Tour

普及+/提高

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

A famous sculptor Cicasso goes to a world tour!

Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will entirely hold the world tour in his native country — Berland.

Cicasso is very devoted to his work and he wants to be distracted as little as possible. Therefore he will visit only four cities. These cities will be different, so no one could think that he has "favourites". Of course, to save money, he will chose the shortest paths between these cities. But as you have probably guessed, Cicasso is a weird person. Although he doesn't like to organize exhibitions, he likes to travel around the country and enjoy its scenery. So he wants the total distance which he will travel to be as large as possible. However, the sculptor is bad in planning, so he asks you for help.

There are n cities and m one-way roads in Berland. You have to choose four different cities, which Cicasso will visit and also determine the order in which he will visit them. So that the total distance he will travel, if he visits cities in your order, starting from the first city in your list, and ending in the last, choosing each time the shortest route between a pair of cities — will be the largest.

Note that intermediate routes may pass through the cities, which are assigned to the tour, as well as pass twice through the same city. For example, the tour can look like that: . Four cities in the order of visiting marked as overlines: [1, 5, 2, 4].

Note that Berland is a high-tech country. So using nanotechnologies all roads were altered so that they have the same length. For the same reason moving using regular cars is not very popular in the country, and it can happen that there are such pairs of cities, one of which generally can not be reached by car from the other one. However, Cicasso is very conservative and cannot travel without the car. Choose cities so that the sculptor can make the tour using only the automobile. It is guaranteed that it is always possible to do.

著名雕塑家西卡索即将开启一场世界巡展!

不过,这其实并非真正意义上的全球巡展。毕竟,并非所有人都有机会欣赏到这位雕塑家的作品,对吧?否则,作品岂不就失去了其独有的稀缺性?因此,西卡索将整场世界巡展完全限定在其祖国——贝尔兰境内举行。

西卡索对其创作极为专注,因而希望在旅途中受到尽可能少的干扰。因此,他仅会访问四座城市。这四座城市必须互不相同,以免让人误以为他有“偏爱”的城市。当然,为节省经费,他将在每一对城市之间均选择最短路径。但正如你可能已经猜到的那样,西卡索是个古怪的人。尽管他并不热衷于举办展览,却十分喜爱环游全国、饱览沿途风光。因此,他希望整个行程的总距离尽可能长。然而,这位雕塑家不擅规划,于是他向你求助。

贝尔兰共有 nn 座城市和 mm 条单向道路。你需要从中选出四座互不相同的城市,作为西卡索的巡展城市,并确定他访问这些城市的顺序。使得:若他按你指定的顺序依次访问这四座城市(即从列表中的第一座城市出发,最终抵达最后一座城市),且在每一对相邻城市之间均选择最短路径,则其全程所行总距离达到最大。

注意:中间各段路径可以经过已被选定为巡展城市的地点,也可能重复经过同一座城市。例如,一次巡展路线可能如下图所示:。图中按访问顺序标出的四座城市(带横线者)为:[1, 5, 2, 4]。

请注意:贝尔兰是一个高科技国家。因此,借助纳米技术,所有道路均被改造为长度完全相等。也正因如此,普通汽车在该国并不流行;从而可能出现这样的情况:某些城市对之间,其中一座城市根本无法通过汽车抵达另一座。然而,西卡索思想非常保守,坚持必须使用汽车出行。因此,请务必选择四座城市,使得雕塑家能仅依靠汽车完成全部行程。题目保证总存在满足条件的方案。

输入格式

In the first line there is a pair of integers n and m (4 ≤ n ≤ 3000, 3 ≤ m ≤ 5000) — a number of cities and one-way roads in Berland.

Each of the next m lines contains a pair of integers u__i, v__i (1 ≤ u__i, v__i ≤ n) — a one-way road from the city u__i to the city v__i. Note that u__i and v__i are not required to be distinct. Moreover, it can be several one-way roads between the same pair of cities.

第一行包含两个整数 nn 和 mm(4 ≤ n ≤ 30004 \leq n \leq 3000,3 ≤ m ≤ 50003 \leq m \leq 5000)——分别表示 Berland 的城市数量和单向道路数量。

接下来的 mm 行中,每行包含两个整数 uiu_i、viv_i(1 ≤ ui, vi ≤ n1 \leq u_i, v_i \leq n)——表示一条从城市 uiu_i 到城市 viv_i 的单向道路。注意:uiu_i 与 viv_i 可以相同。此外,同一对城市之间可能存在多条单向道路。

输出格式

Print four integers — numbers of cities which Cicasso will visit according to optimal choice of the route. Numbers of cities should be printed in the order that Cicasso will visit them. If there are multiple solutions, print any of them.

输出四个整数——即Cicasso按照最优路径选择所要访问的城市编号。城市编号应按Cicasso实际访问的顺序输出。若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    8 9
    1 2
    2 3
    3 4
    4 1
    4 5
    5 6
    6 7
    7 8
    8 5

    输出#1

    2 1 8 7

说明/提示

Let d(x, y) be the shortest distance between cities x and y. Then in the example d(2, 1) = 3, d(1, 8) = 7, d(8, 7) = 3. The total distance equals 13.

设 d(x,y)d(x, y) 表示城市 xx 与 yy 之间的最短距离。则在该示例中,d(2,1)=3d(2, 1) = 3,d(1,8)=7d(1, 8) = 7,d(8,7)=3d(8, 7) = 3。总距离为 1313。

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

首页