CF1129A1 Toy Train (Simplified)

题目描述

Alice 有一辆玩具火车,和 $n$ 个首尾相接的站台(即火车位于第 $i$($1\le i

输入格式

第一行包含两个整数 $n,m$($2\le n\le 200$;$1\le m\le 200$),意义如上所示。 接下来 $m$ 行,每行包含两个整数 $a_i,b_i$($1\le a_i,b_i\le n$;$a_i\neq b_i$),即该糖果的初始站台与要被运往的站台。

输出格式

一行 $n$ 个整数,第 $i$ 个整数表示火车从 $i$ 站台出发时将所有糖果运送完毕至少应经过多少站台。

说明/提示

Consider the second sample. If the train started at station $ 1 $ , the optimal strategy is as follows. 1. Load the first candy onto the train. 2. Proceed to station $ 2 $ . This step takes $ 1 $ second. 3. Deliver the first candy. 4. Proceed to station $ 1 $ . This step takes $ 1 $ second. 5. Load the second candy onto the train. 6. Proceed to station $ 2 $ . This step takes $ 1 $ second. 7. Deliver the second candy. 8. Proceed to station $ 1 $ . This step takes $ 1 $ second. 9. Load the third candy onto the train. 10. Proceed to station $ 2 $ . This step takes $ 1 $ second. 11. Deliver the third candy. Hence, the train needs $ 5 $ seconds to complete the tasks. If the train were to start at station $ 2 $ , however, it would need to move to station $ 1 $ before it could load the first candy, which would take one additional second. Thus, the answer in this scenario is $ 5+1 = 6 $ seconds.