Angry Cows#10664

Angry Cows

6 seconds
256 megabytes
Medium

In recent years, there has been a rapid spread of Extremely Green Oxen Illness (EGOI) — a disease that makes cows dangerous for tourists. After several incidents, it was decided that we must separate the areas where cows graze from the areas visited by tourists.

You have a map of the Alps. The map consists of regions. Each region can be either inhabited by cows, a tourist region, or empty. Some pairs of these regions are connected by bidirectional roads. Each road has a non-negative length. (In terms of graph theory, the map is an undirected weighted graph.)

You can build walls in some regions. Once you build a wall in a region, that region becomes inaccessible to both cows and tourists — they can no longer pass through that region.

Your task is to choose a set of regions where walls will be built. This set of regions must satisfy the following conditions:

If there are several ways to achieve the above, we are only concerned with the ease of wall maintenance. The walls are maintained by special teams. There is exactly one such team in each tourist region.

For any region , we define its remoteness as the minimal length of a path between and some tourist region. (Path length is the sum of road lengths. Note that the path may pass through walls and cow regions — the maintenance team servicing the wall can freely move anywhere using any means.)

The remoteness of a set of regions is the maximum remoteness of any region in this set.

Among all sets of wall regions that satisfy all the given conditions, find and return a set with the smallest possible remoteness. If there are several such sets, return any one of them.

Note that the number of selected regions does not matter. In other words, you are not required to use the minimum number of walls.

Input

The first line contains two integers and (2 \leq n \leq 3 \cdot 10^5, n-1 \leq m \leq 3 \cdot 10^5) — the number of regions and roads, respectively. The regions are numbered from to .

The second line contains integers t_1, \ldots, t_n, where t_i is if the -th region is inhabited by cows, if it is empty, and if it is a tourist region.

The next lines describe the roads. The -th line contains three integers a_j, b_j, and \ell_j (1 \le a_j < b_j \le n, 0 \le \ell_j \le 10^9), representing a road between regions a_j and b_j of length \ell_j.

It is guaranteed that:

  • there is at most one road connecting any two regions,

  • currently it is possible to travel between any two regions, using zero or more roads,

  • there is at least one region inhabited by cows,

  • there is at least one tourist region.

Output

If it is impossible to build walls as stated in the problem, output -1.

Otherwise, the first line should contain the number — the number of regions where you want to build walls. The second line should contain integers — the numbers of the regions where you want to build walls. (These numbers must be distinct, between and , inclusive. They do not need to be in any particular order.)

Your output will be accepted if the set meets all requirements and its remoteness is minimal.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading

Note

In all examples, blue denotes tourist regions, brown denotes regions inhabited by cows, and orange denotes walls.

In the first example, the minimal possible remoteness is , achieved by placing walls in regions , , and . Note that we cannot place walls in regions , , and , even though we get remoteness , because then it would be impossible to travel between tourist regions and without passing through walls.

In the second example, the remoteness of region is , the remoteness of region is , since this can be achieved via the path –––. (Reminder: teams can move through walls and cow regions.) Therefore, we should place walls in regions and (not ), which gives a remoteness of .

Scoring

Block ( points): n \le 10.

Block ( points): all lengths \ell_j = 0.

Block ( points): there is exactly one tourist region.

Block ( points): there are exactly n-1 roads (that is, the graph is a tree).

Block ( points): n, m \le 2000 and all lengths \ell_j = 1.

Block ( points): no additional constraints.