Google 10月份在线笔试ProblemB(个人代码,未必最优,请不吝赐教)

本文介绍了一个Google在线笔试题目,涉及城市地铁系统的时间优化问题。内容包括地铁线路、站点、等待时间和转乘隧道的描述,以及如何计算从一个站点到另一个站点的最短时间。解题思路是利用有向带权图的最短路径算法解决。
摘要由CSDN通过智能技术生成

Problem

Tom is taking metros in the city to go from station to station.

The metro system in the city works like this:

  • There are N metro lines in the city: line 1, line 2, ..., line N.
  • For each metro i, there are SNi stations. Let's assume they are Si,1,Si,2, ... , Si,SNi. These stations are ordered from one end point to the other end point. The metro is running in both directions. In other words, the metro is going from Si,1 -> Si,2 -> ... -> Si,SNi, and Si,SNi -> Si,SNi-1 -> ... -> Si,1. You can take the metro from any station and get off at any station. It takes a certain time to travel from one station to the next station. It takes Timei,1 minutes to travel from Si,1 to Si,2Timei,2 minutes to travel from Si,2 to Si,3, etc. It takes the same time in the other direction.
  • There are M transfer tunnels. Each transfer tunnel connects two stations of different metro lines. It takes a certain amount of time to travel through a tunnel in either direction. You can get off the metro at one end of the tunnel and walk through the tunnel to the station at the another end.
  • When you arrive at a metro station of line i, you need to wait Wi minutes for the next metro.

Now, you are going to travel from one station to another. Find out the shortest time you need.

Input

The first line of the input gives the number of test cases, TT test cases follow.

Each test case starts with an integer N, the number of metro lines. N metros descriptions follow. Each metro description starts with two integers SNi and Wi, the number of stations and th

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值