103. Traffic Lights

9 篇文章 0 订阅

Time limit per test: 0.25 second(s)
Memory limit: 4096 kilobytes
input: standard
output: standard



In the city of Dingilville the traffic is arranged in an unusual way. There are junctions and roads connecting the junctions. There is at most one road between any two different junctions. There is no road connecting a junction to itself. Travel time for a road is the same for both directions. At every junction there is a single traffic light that is either blue or purple at any moment. The color of each light alternates periodically: blue for certain duration and then purple for another duration. Traffic is permitted to travel down the road between any two junctions, if and only if the lights at both junctions are the same color at the moment of departing from one junction for the other. If a vehicle arrives at a junction just at the moment the lights switch it must consider the new colors of lights. Vehicles are allowed to wait at the junctions. You are given the city map which shows:
  • the travel times for all roads (integers)
  • the durations of the two colors at each junction (integers)
  • and the initial color of the light and the remaining time (integer) for this color to change at each junction.

    Your task is to find a path which takes the minimum time from a given source junction to a given destination junction for a vehicle when the traffic starts. In case more than one such path exists you are required to report only one of them.

    Input
    The first line contains two numbers: The id-number of the source junction and the id-number of the destination junction. The second line contains two numbers:N,M. The followingN lines contain information on N junctions. The (i+2)'th line of the input file holds information about the junctioni :Ci,riC,tiB,tiP whereCi is eitherB forblue orP for purple, indicating the initial color of the light at the junctioni. Finally, the nextM lines contain information onM roads. Each line is of the form:i,j, lij wherei andj are the id-numbers of the junctions which are connected by this road. 2 ≤N ≤ 300 whereN is the number of junctions. The junctions are identified by integers 1 throughN. These numbers are called id-numbers. 1 ≤M ≤ 14000 whereM is the number of roads. 1 ≤ lij ≤ 100 wherelij is the time required to move from junctioni toj using the road that connects i and j. 1 ≤tiC ≤ 100 wheretiC is the duration of the colorc for the light at the junctioni. The index c is either 'B' for blue or 'P' for purple. 1 ≤riCtiC whereriC is the remaining time for the initial colorc at junctioni.

    Output
    If a path exists:
  • The first line will contain the time taken by a minimum-time path from the source junction to the destination junction.
  • Second line will contain the list of junctions that construct the minimum-time path you have found. You have to write the junctions to the output file in the order of travelling. Therefore the first integer in this line must be the id-number of the source junction and the last one the id-number of the destination junction.

    If a path does not exist:
  • A single line containing only the integer 0.

    Example(s)
    sample input
    sample output
    1 4
    4 5
    B 2 16 99
    P 6 32 13
    P 2 87 4
    P 38 96 49
    1 2 4
    1 3 40
    2 3 75
    2 4 76
    3 4 77
    
    127
    1 2 4
    

    一个城市有很多路口,每个路口有一个交通灯,灯的颜色是紫色或蓝色,每两个路口之间最多有一条路,路口没有通向自己的路,当一条路两段路口灯颜色一样的时候,车可以通过这条路,如果车在路中行驶的时候不用考虑灯的颜色,求从源点到目的地的最短时间

先给出两个数         起点s                 终点t

接下来两个数         路口数量n         路的数量m

接下来n行              B/P初始此路口灯的颜色c     初始颜色在路口持续的时间tc     每次蓝灯持续的时间tb     每次紫灯持续的时间tp

接下来m行             路口u     路口v     通过路uv需要的时间








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值