Easter is fast approaching but you stil need the dyes to colour all those eggs,
here at the Easter Scientific Developers Inc. (easters.dev for short).
So you head into the garden, to see if you can acquire any colour from there.
The gardeners tell you they have an array of plants which can be used to make
some blue dye (Indigofera tinctoria, Isatis tinctoria, etc.).
But they have lost oversight of how all these plants are related to each other.
So before any of these plants can be planted you have to understand their genetic map.
Your input consists of two parts seperated by two blank lines, the first part
is thus this genetic map, and the second part is the field of plants currently
planted. Take this genetic map as an example:
a--31--b
|x-2-y-6-v
4| |
75 8
|| |
cz-3-w
|
9
|
u
Every plant is identified by a single letter and is connected with up to four
other plants. The connections always starts with either -
or
|
and can only go straight up, down, left or right. The genetic
distance between two plants is written on their connections. It is always
written top-to-bottom or left-to-right.
In this example, a has a genetic distance of
47 from c, while the plants
c and z are not related.
If two plants are only indirectly connected, their genetic distance is the
smallest sum of genetic distances from any path between them. The plants, that
only have one direct connection to a related plant, are called extant.
Before we can grow any of them we have to make sure we understand their
genetics: take any extant plant and get the genetic distance to any other extant
plant, if they are related. For the genetic map in the example, we would have
the following connections:
u to v: 22
b to c: 78
In total, they sum up to 100
.
What's the sum of all the genetic distances between all extant plants in your
genetic map?