Unit conversion ratio queries with modular answers
I was asked this
No reports yet. Sign in to say where you were asked it.
You have n units, numbered 0 to n - 1, split into separate families: units in one family convert into each other, units from different families never do. You are given conversion facts between pairs of units (one unit equals some multiple of another). Answer a list of queries, each asking how many of unit b make one unit a, or that the conversion is impossible because the two units sit in different families. Ratios can grow huge, so report them modulo a given number (division then becomes multiplication by a modular inverse). Build the families once, then answer each query fast.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
