#P6770. Suspect Cow Identification

    ID: 19977 Type: Default 1000ms 256MiB

Suspect Cow Identification

Suspect Cow Identification

Farmer John's barn (located at node \(1\)) has been robbed. Fortunately, a satellite captured an image of his farm exactly \(M\) seconds before the robbery. The farm is represented as a graph with \(F\) nodes (grasslands) and \(P\) bidirectional roads connecting them. Each road has an associated travel time (between 1 and 70000 seconds) and note that there may be multiple roads between the same pair of nodes.

There are \(C\) cows on the farm, each located at a certain node as captured in the satellite image. In order for a cow to be a suspect, it must be possible to travel from the barn (node 1) to the cow's location within \(M\) seconds (using the shortest possible path). Your task is to determine which cows could have reached their current location from the barn within \(M\) seconds. Output the number of such cows, and then list their identifiers (the order in which they are given in the input, starting from 1) in ascending order.

inputFormat

The first line contains four integers \(F\), \(P\), \(C\), and \(M\), where \(F\) is the number of nodes, \(P\) is the number of roads, \(C\) is the number of cows, and \(M\) is the maximum allowed travel time.

The next \(P\) lines each contain three integers \(u\), \(v\), and \(t\), representing a bidirectional road between nodes \(u\) and \(v\) with travel time \(t\). Note that there may be duplicate roads.

The last line contains \(C\) space-separated integers, where the \(i^{th}\) integer represents the node at which cow \(i\) is located.

outputFormat

On the first line, output the number of cows that could have reached their current location from the barn within \(M\) seconds.

On the second line, output the identifiers of these cows in ascending order (separated by a space). If no cow qualifies, output 0 on the first line and leave the second line empty.

sample

4 4 3 10
1 2 5
2 3 5
1 3 15
3 4 3
2 3 4
2

1 2

</p>