307355: CF1344E. Train Tracks
Memory Limit:256 MB
Time Limit:5 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Train Tracks
题意翻译
给定 $n$ 个点的一棵树,以 $1$ 为根,边有边权。 有 $m$ 辆从 $1$ 开始到 $s_i$ 的火车,每个火车有一个初始时刻 $t_i$,在初始时刻时从根出发,向着目标 $s_i$ 前进,当火车在 $x$ 时刻到达一个点 $u$ 时,假设下一个路径上的点是 $v$,两点间边权是 $d$,则在 $x+d$ 时刻到达 $v$,火车在到达目标点后停止。 由于每个点可能可以到达多个点,每个点有且仅有一个当前时刻可以到的儿子,每秒钟只能切换某一个点可以到的儿子,切换比火车开动先进行,若一辆火车走向了非目标方向的点,则立刻自爆。每个点初始能到的儿子是确定的。 求出能否不发生自爆,如果不能,第一次自爆最晚什么时候发生?在此基础上,至少切换多少次一个点可以到的儿子。题目描述
That's right. I'm a Purdue student, and I shamelessly wrote a problem about trains. There are $ n $ stations and $ m $ trains. The stations are connected by $ n-1 $ one-directional railroads that form a tree rooted at station $ 1 $ . All railroads are pointed in the direction from the root station $ 1 $ to the leaves. A railroad connects a station $ u $ to a station $ v $ , and has a distance $ d $ , meaning it takes $ d $ time to travel from $ u $ to $ v $ . Each station with at least one outgoing railroad has a switch that determines the child station an incoming train will be directed toward. For example, it might look like this: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1344E/e8d20581464bf556f874b5b2e7d7c090037ff45d.png) Here, stations $ 1 $ and $ 3 $ have switches directed toward stations $ 2 $ and $ 4 $ , respectively. Initially, no trains are at any station. Train $ i $ will enter station $ 1 $ at time $ t_i $ . Every unit of time, starting at time $ 1 $ , the following two steps happen: 1. You can switch at most one station to point to a different child station. A switch change takes effect before step $ 2 $ . 2. For every train that is on a station $ u $ , it is directed toward the station $ v $ indicated by $ u $ 's switch. So, if the railroad from $ u $ to $ v $ has distance $ d $ , the train will enter station $ v $ in $ d $ units of time from now. Every train has a destination station $ s_i $ . When it enters $ s_i $ , it will stop there permanently. If at some point the train is going in the wrong direction, so that it will never be able to reach $ s_i $ no matter where the switches point, it will immediately explode. Find the latest possible time of the first explosion if you change switches optimally, or determine that you can direct every train to its destination so that no explosion occurs. Also, find the minimum number of times you need to change a switch to achieve this.输入输出格式
输入格式
The first line contains two integers $ n $ and $ m $ ( $ 1\le n,m\le 10^5 $ ) — the number of stations and trains, respectively. The next $ n-1 $ lines describe the railroads. The $ i $ -th line contains three integers $ u,v,d $ ( $ 1\le u,v\le n $ , $ 1\le d\le 10^9 $ ), denoting a railroad from station $ u $ to station $ v $ with distance $ d $ . It is guaranteed that the railroads form a tree rooted at station $ 1 $ . The switch of a station $ u $ is initially directed towards the last outgoing railroad from $ u $ that appears in the input. The next $ m $ lines describe the trains. The $ i $ -th line contains two integers $ s_i,t_i $ ( $ 1\le s_i\le n $ , $ 1\le t_1<t_2<\cdots<t_m\le 10^9 $ ) — the destination station and the time the $ i $ -th train enters station $ 1 $ , respectively.
输出格式
Output two integers: the latest possible time of the first explosion (or $ -1 $ if it is possible to never have an explosion) and the minimum number of switch changes to achieve it.
输入输出样例
输入样例 #1
5 4
1 2 1
1 3 2
3 4 1
3 5 3
2 1
4 2
2 6
5 10
输出样例 #1
-1 6
输入样例 #2
5 4
1 2 1
1 3 2
3 4 1
3 5 3
5 1
4 2
4 3
2 4
输出样例 #2
4 0
输入样例 #3
11 6
1 2 1
1 3 2
3 4 1
3 5 2
5 6 1
5 7 2
7 8 1
7 9 2
9 10 1
9 11 1
2 1
8 3
6 5
10 7
4 9
2 11
输出样例 #3
11 4