Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const [trainCars, numTickets, numRoutes] = readline().split(' ').map(n => +n)
- const colors = ['red', 'yellow', 'green', 'blue', 'white', 'black', 'orange', 'pink', 'engine']
- // Player's hand: for each color type, a number of cards
- const hand = {}
- readline().split(' ').forEach((num, i) => {
- hand[colors[i]] = +num
- })
- // Player's tickets: two cities and a number of earned points
- const tickets = Array.from({length: numTickets}, () => {
- const [p, from, to] = readline().split(' ')
- return {points: +p, from, to}
- }).sort((a, b) => b.points - a.points)
- // Possible routes: two cities, a number of required cards and engines
- const routes = Array.from({length: numRoutes}, () => {
- const [l, e, c, from, to] = readline().split(' ')
- return {length: +l, requiredEngines: +e, color: c.toLowerCase(), from, to}
- })
- // Graph of cities, by name. Contains an array of linked cities (route index)
- const mapGraph = {}
- routes.forEach(({from, to}, i) => {
- if (!(from in mapGraph)) {
- mapGraph[from] = []
- }
- mapGraph[from].push(i)
- if (!(to in mapGraph)) {
- mapGraph[to] = []
- }
- mapGraph[to].push(i)
- })
- /*printErr(JSON.stringify(hand, null, 2))
- printErr(JSON.stringify(tickets, null, 2))
- printErr(JSON.stringify(routes, null, 2))
- printErr(JSON.stringify(mapGraph, null, 2))*/
- const computeRouteScore = route => {
- switch(route.length) {
- case 1: return 1
- case 2: return 2
- case 3: return 4
- case 4: return 7
- case 6: return 15
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement