A8310 | Subway
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
输出格式
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted