#K77227. Net Effects in Ecological Interactions
Net Effects in Ecological Interactions
Net Effects in Ecological Interactions
You are given a number of interactions among different species in an ecosystem. Each interaction is represented as a tuple of two species and the type of interaction between them; the type can be either help
or harm
.
The net effect of one species on another is the sum of all the help (+1) and harm (-1) interactions from the first species to the second. The order of the species is determined by the order in which they first appear in the input (first species in an interaction is considered first if not seen before, then the second).
If there are no interactions, output a special representation (i.e. []
).
Your task is to compute the net effect matrix and print it. Each row corresponds to a species and each column corresponds to the effect on another species. Each cell should contain an integer value. Use LaTeX formatting for any formulas in the explanation. For instance, the effect of species \(i\) on species \(j\) can be denoted as \(E_{ij}\).
inputFormat
The input is read from standard input (stdin
) and has the following format:
M s1 s2 effect s1 s2 effect ... (M lines)
Here, M
is an integer denoting the number of interactions. Each of the following M
lines contains three strings: the first species s1
, the second species s2
, and the interaction type which is either help
or harm
.
outputFormat
The output is printed to standard output (stdout
). For a non-empty list of interactions, print the net effect matrix where each row is printed on a separate line. Each number in a row should be space-separated. If there are no interactions (i.e. M = 0
), print []
on a single line.
6
Lion Deer help
Deer Grass help
Grass Lion harm
Lion Grass help
Deer Lion harm
Grass Deer help
0 1 1
-1 0 1
-1 1 0
</p>