CF131D.Subway

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A subway scheme, classic for all Berland cities is represented by a set of n stations connected by n passages, each of which connects exactly two stations and does not pass through any others. Besides, in the classic scheme one can get from any station to any other one along the passages. The passages can be used to move in both directions. Between each pair of stations there is no more than one passage.

Berland mathematicians have recently proved a theorem that states that any classic scheme has a ringroad. There can be only one ringroad. In other words, in any classic scheme one can find the only scheme consisting of stations (where any two neighbouring ones are linked by a passage) and this cycle doesn't contain any station more than once.

This invention had a powerful social impact as now the stations could be compared according to their distance from the ringroad. For example, a citizen could say "I live in three passages from the ringroad" and another one could reply "you loser, I live in one passage from the ringroad". The Internet soon got filled with applications that promised to count the distance from the station to the ringroad (send a text message to a short number...).

The Berland government decided to put an end to these disturbances and start to control the situation. You are requested to write a program that can determine the remoteness from the ringroad for each station by the city subway scheme.

一种在所有伯兰德城市中经典的地铁线路图,由 nn 个车站和 nn 条通道构成;每条通道恰好连接两个车站,且不经过其他任何车站。此外,在经典线路图中,任意两个车站之间均可通过通道相互到达。通道是双向通行的。任意两个车站之间至多只有一条通道。

伯兰德数学家最近证明了一个定理:任何经典线路图都包含且仅包含一个环线(ringroad)。换言之,在任意经典线路图中,总存在唯一一个由若干车站构成的环(其中任意两个相邻车站由一条通道直接相连),且该环中每个车站至多出现一次。

这一发现产生了巨大的社会影响——如今人们可以根据各车站到环线的距离来比较车站的“远近”。例如,一位市民可以说:“我住的车站离环线有三条通道的距离”,另一位则可回应:“你真惨,我住的车站离环线只有一条通道的距离”。互联网上很快充斥着各类声称能计算某车站到环线距离的应用程序(只需向一个短号码发送短信……)。

伯兰德政府决定终结此类混乱局面,并开始对局势进行管控。现要求你编写一个程序,根据该城市的地铁线路图,计算出每个车站到环线的最短距离。

输入格式

The first line contains an integer n (3 ≤ n ≤ 3000), n is the number of stations (and trains at the same time) in the subway scheme. Then n lines contain descriptions of the trains, one per line. Each line contains a pair of integers x__i, y__i (1 ≤ x__i, y__i ≤ n) and represents the presence of a passage from station x__i to station y__i. The stations are numbered from 1 to n in an arbitrary order. It is guaranteed that x__i ≠ y__i and that no pair of stations contain more than one passage. The passages can be used to travel both ways. It is guaranteed that the given description represents a classic subway scheme.

第一行包含一个整数 nn(3≤n≤30003 \leq n \leq 3000),表示地铁线路图中的车站数量(同时也是列车数量)。接下来的 nn 行每行描述一列列车,共 nn 行。每行包含一对整数 xi, yix_i,\, y_i(1≤xi, yi≤n1 \leq x_i,\, y_i \leq n),表示存在一条从车站 xix_i 到车站 yiy_i 的通道。车站编号为 11 至 nn,编号顺序任意。保证 xi≠yix_i \neq y_i,且任意两个车站之间至多只有一条通道。通道为双向通行。保证所给描述构成一个经典的地铁线路图。

输出格式

Print n numbers. Separate the numbers by spaces, the i-th one should be equal to the distance of the i-th station from the ringroad. For the ringroad stations print number 0.

输出 n 个数字,用空格分隔;其中第 i 个数字应等于第 i 个车站到环形公路的距离。对于位于环形公路上的车站,输出数字 0。

输入输出样例

  • 输入#1

    4
    1 3
    4 3
    4 2
    1 2

    输出#1

    0 0 0 0
  • 输入#2

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

    输出#2

    0 0 0 1 1 2

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

首页