Imperfect Imperial Units
시간 제한4초메모리 제한1024 MB
단위 변환 방정식들이 그래프를 이루고 있을 때, 한 단위의 값을 다른 단위로 변환하는 질의에 답하거나 불가능하다고 출력합니다.
문제
You are writing a paper for the Beta Astronomy Physics Conference about your recent discovery on grey holes. One of your collaborators has performed a huge number of measurements, which you would like to analyse in order to draw some conclusions. The only problem is: the data is measured in a wide variety of units, and to your disgust, they appear to use a mix of the imperial and metric systems. To simplify your analysis, you need to convert all these measurements into a different unit.
입력
The input consists of:
- One line with two integers and (, ), the number of unit conversion equations and the number of queries to answer.
- lines, each defining a unit conversion in the format "
1 <unit> = <value> <unit>". - lines, each with a query in the format "
<value> <unit> to <unit>".
In these formats, "<value>" is a floating-point number (, with at most digits after the decimal point) and "<unit>" is a string of at most English lowercase letters (a-z). A unit in a query is guaranteed to be defined in at least one unit conversion equation. Every unit can be converted into every other unit in at most one way.
출력
For every query, output the value of the requested unit, or "impossible" if the query cannot be answered.
Your answers should have a relative error of at most .