#abc307f. F - Virus 2
F - Virus 2
Score : points
问题描述
有 个房间,编号为 , , , ,每个房间内住着一个人,并且有 条走廊连接两个不同的房间。第 条走廊连接了房间 和房间 ,其长度为 。
有一天(我们称这一天为第 天),住在房间 的 个人(新)感染了一种病毒。接下来的 天中,在第 天(),感染以以下方式扩散:
在第 天夜晚结束时已感染的人,在第 天夜晚结束时仍然保持感染状态。
对于未感染者,如果他们在第 天夜晚结束时所居住的房间与至少一个感染者的房间之间的距离小于等于 ,则他们将被新感染。这里,房间 和 之间的距离定义为仅使用走廊从房间 移动到房间 时,所有可能走廊长度之和的最小值。若无法仅通过走廊从房间 移动到房间 ,则设定该距离为 。
对于每个 (),请输出住在房间 的人在哪一天被新感染。如果在第 天夜晚结束时他们仍未被感染,则输出 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are rooms numbered , , , , each with one person living in it, and corridors connecting two different rooms. The -th corridor connects room and room with a length of .
One day (we call this day ), the people living in rooms got (newly) infected with a virus. Furthermore, on the -th of the following days , the infection spread as follows.
People who were infected at the end of the night of day remained infected at the end of the night of day .
For those who were not infected, they were newly infected if and only if they were living in a room within a distance of from at least one room where an infected person was living at the end of the night of day . Here, the distance between rooms and is defined as the minimum possible sum of the lengths of the corridors when moving from room to room using only corridors. If it is impossible to move from room to room using only corridors, the distance is set to .
For each (), print the day on which the person living in room was newly infected. If they were not infected by the end of the night of day , print .
Constraints
- All are different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines.
The -th line should contain the day on which the person living in room was newly infected.
Sample Input 1
4 4
1 2 2
2 3 1
2 4 3
3 4 2
1
1
2
3 3
Sample Output 1
0
1
1
2
The infection spreads as follows.
- On the night of day , the person living in room gets infected.
- The distances between room and rooms are , respectively. Thus, since , the people living in rooms and are newly infected on the night of day .
- The distance between rooms and is . Thus, since , the person living in room also gets infected on the night of day .
Therefore, the people living in rooms were newly infected on days , respectively, so print in this order on separate lines.
Sample Input 2
7 7
1 2 2
2 3 3
3 4 1
4 5 1
5 6 3
3 7 1
4 7 1
2
1 6
2
2 3
Sample Output 2
0
1
2
-1
2
0
-1
Sample Input 3
5 1
1 2 5
2
1 3
3
3 7 5
Sample Output 3
0
2
0
-1
-1
Note that it is not always possible to move between any two rooms using only corridors.
update @ 2024/3/10 08:42:17