简单的拓扑图dp..
A(i, j), B(i, j) 表示从点 i 长度为 j 的两种路径是否存在. 用bitset就行了
时间复杂度O(m)
----------------------------------------------------------------
----------------------------------------------------------------
3890: [Usaco2015 Jan]Meeting Time
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 95 Solved: 65
[ Submit][ Status][ Discuss]
Description
Bessie and her sister Elsie want to travel from the barn to their favorite field, such that they leave at exactly the same time from the barn, and also arrive at exactly the same time at their favorite field. The farm is a collection of N fields (1 <= N <= 100) numbered 1..N, where field 1 contains the barn and field N is the favorite field. The farm is built on the side of a hill, with field X being higher in elevation than field Y if X < Y. An assortment of M paths connect pairs of fields. However, since each path is rather steep, it can only be followed in a downhill direction. For example, a path connecting field 5 with field 8 could be followed in the 5 -> 8 direction but not the other way, since this would be uphill. Each pair of fields is connected by at most one path, so M <= N(N-1)/2. It might take Bessie and Elsie different amounts of time to follow a path; for example, Bessie might take 10 units of time, and Elsie 20. Moreover, Bessie and Elsie only consume time when traveling on paths between fields -- since they are in a hurry, they always travel through a field in essentially zero time, never waiting around anywhere. Please help determine the shortest amount of time Bessie and Elsie must take in order to reach their favorite field at exactly the same moment.
给出一个n个点m条边的有向无环图,每条边两个边权。
n<=100,没有重边。
然后要求两条长度相同且尽量短的路径,
路径1采用第一种边权,路径2采用第二种边权。
没有则输出”IMPOSSIBLE”
Input
Output
Sample Input
1 3 1 2
1 2 1 2
2 3 1 2
Sample Output
SOLUTION NOTES:
Bessie is twice as fast as Elsie on each path, but if Bessie takes the
path 1->2->3 and Elsie takes the path 1->3 they will arrive at the
same time.
HINT
Source