Tourist Petr
Time limit2sMemory limit1024 MB
Find a simple path of at most 4 cities with the largest total enjoyment, given each city's value and the train routes between cities, and print the cities in visiting order.
- Level
Medium5 of 10
- Topics
- Graph, Brute force, Sorting
- Solved
- No attempts yet
Problem
Vera met Petr, a friendly volleyball player and tractor driver, while on vacation in a Warm Country. Petr, a tourist, plans to travel through European cities after the vacation. Europe has a well-developed transport system. There are cities that interest Petr and night train routes. Each route connects two different cities, and the trip takes one night. Trains run in both directions.
Petr wants the whole trip to take no more than four days. He spends exactly one day sightseeing in each city, and he spends each night on a night train between cities. Petr does not want to visit any city more than once.
For each city, Petr has estimated his expected enjoyment of visiting it. Find a route that gives Petr the greatest total enjoyment.
Input
The first line contains two integers and (), the number of cities and the number of train routes.
The second line contains integers (), where is the expected enjoyment of visiting city .
Each of the next lines describes a route with two different integers and (), the numbers of the cities that the route connects. There is at most one route between any pair of cities.
Output
On the first line, print the number of cities on the optimal route (). On the second line, print the numbers of these cities in the order of the visit. Cities are numbered starting from 1. If several optimal routes exist, print any of them.