Under construction

Still being built. Things may change

Efficient Inspection

Interview

Time limit1sMemory limit1024 MB

Summary
On a tree, find the shortest closed walk from node 0 that visits every required node, and print its length and the route taken.
Level

Easy3 of 10

Topics
Tree, DFS
Solved
No attempts yet

Problem

The Joseon court is about to launch a large-scale inspection for corruption. The problem is that the officials must travel across the whole country in person, which is exhausting and takes a lot of time. The king wants to run the inspection efficiently with help from you, who come from the future.

Each official was given a map and a table listing the places that official must visit. Every place on the map has a unique number from 00 to N−1N-1, and the palace is number 00. Each place is connected to others by roads of the same length that can be traveled in both directions. All officials start at the palace (0), visit every designated place, and return to the palace to report to the king. When moving from one place to another, they must follow the given roads and cannot change direction partway along a road.

The maps given to the officials are designed as follows.

  • All places are connected to each other by exactly N−1N-1 roads. Each road connects only its two end places.
  • There is exactly one path between any two places.
  • Traveling along one road takes the same time, one unit of time 11.

Given the map and table for one official, find one optimal route that starts at the palace (0), visits all designated places, and returns to the palace in the minimum possible time.

Input

The first line contains the number of places NN and the number of places MM that the official must visit, separated by a space. (1≤N≤100 0001 \leq N \leq 100\,000; 1≤M≤N1 \leq M \leq N)

The second line contains MM distinct place numbers p1,p2,…,pMp_1, p_2, \dots, p_M that the official must visit, separated by spaces. (0≤pi≤N−10 \leq p_i \leq N-1)

The next N−1N-1 lines give, on line i+2i+2, the two end places uiu_i and viv_i of the ii-th road, separated by a space. (ui≠viu_i \neq v_i; 0≤ui,vi≤N−10 \leq u_i, v_i \leq N-1)

Output

On the first line, print the minimum time TT (in units of time) needed for the trip.

On the second line, print the T+1T+1 place numbers visited along one optimal route, in order, separated by spaces.

Examples2

  1. Example 1

    Input
    7 3
    3 4 5
    0 6
    0 3
    6 4
    6 5
    3 2
    3 1
    
    Expected output
    8
    0 6 4 6 5 6 0 3 0
    
  2. Example 2

    Input
    7 5
    6 3 2 1 0
    0 1
    0 4
    4 6
    6 2
    4 3
    4 5
    
    Expected output
    10
    0 1 0 4 6 2 6 4 3 4 0