#P9274. [AGM 2023 资格赛] 建设计划

[AGM 2023 资格赛] 建设计划

Problem Description

A group of engineers is planning to build a new factory. To make their factory reliable, they want to produce various items at a constant and steady rate in units per second. They can use different machines to craft these materials. Each machine has its own speed, which affects the crafting process. Each material has its own crafting recipe, and it must be executed on a specific machine.

You are given the description of each machine and the recipes for every required material and intermediate material. You are also given a list of materials that must be produced at a specified rate so that the factory is reliable.

We say a machine configuration is optimal if and only if, after removing any single machine from the configuration, the production rate of at least one material becomes lower than the required rate.

You need to find an optimal configuration.

Input Format

The first line contains an integer M(1M100)M(1≤M≤100), the number of machine types we have. In the next MM lines, each line contains a string n(1n30)n(1≤|n|≤30) and a number s(0.01s100)s(0.01≤s≤100), representing the machine name and its speed.

The next line contains an integer N(1N100)N(1≤N≤100), the number of recipes.

Then follow NN groups of recipes. For each recipe group: in the first line of the recipe, a string p(1p30)p(1≤|p|≤30) is the name of the material to be crafted, a string l(1l30)l(1≤|l|≤30) is the name of the machine used in the crafting process, and a number t(0.01t100)t(0.01≤t≤100) is the time (in seconds) required to craft the material at normal speed. On the next line, there is a number k(0k15)k(0≤k≤15), the number of types of additional materials required to produce this material. In the following kk lines, each line contains a string n(1n30)n(1≤|n|≤30), the name of a required material, and an integer c(1c10)c(1≤c≤10), the number of units of that material required.

The next line contains an integer Q(1Q100)Q(1≤Q≤100), the number of demands.

Each of the next QQ lines contains a string m(1m30)m(1≤|m|≤30), the name of the material that must be produced for this demand, and an integer c(1c10)c(1≤c≤10), the number of units of that material that must be produced per second.

Both ss and tt are floating-point numbers with two decimal places. It is guaranteed that an optimal configuration exists. It is guaranteed that in an optimal solution, the production rate of each material does not exceed 10910^9 units per second, and each material can be crafted using a unique recipe. It is also guaranteed that the dependency graph of recipe requirements has no cycles.

Output Format

Output a total of NN lines. On the ii-th line, output pi,li,rip_i,l_i,r_i, where rir_i is the number of machines used to execute the ii-th recipe.

3
assembler 0.50
furnace 0.50
mining_well 0.55
6
iron_plate furnace 3.20
1
iron_ore 1
copper_plate furnace 3.20
1
copper_ore 1
iron_ore mining_well 1.00
0
copper_ore mining_well 1.00
0
copper_cable assembler 0.50
1
copper_plate 1
electronic_circuit assembler 0.50
2
iron_plate 1
copper_cable 3
1
electronic_circuit 10
iron_plate furnace 64
copper_plate furnace 192
iron_ore mining_well 19
copper_ore mining_well 55
copper_cable assembler 30
electronic_circuit assembler 10
3
assembler 0.50
furnace 0.50
mining_well 0.55
4
iron_plate furnace 3.20
1
iron_ore 1
iron_ore mining_well 1.00
0
iron_gear assembler 0.50
1
iron_plate 2
transport_belt assembler 0.50
2
iron_plate 1
iron_gear 1
1
transport_belt 7
iron_plate furnace 135
iron_ore mining_well 39
iron_gear assembler 7
transport_belt assembler 7

Hint

Translated by ChatGPT 5