Question: Solve with C++: Problem 1: Resources Michael is an economist who researches the impact of various industries on the natural environment. He wants to know

Solve with C++:

Problem 1: Resources Michael is an economist who researches the impact of various industries on the natural environment. He wants to know if a certain industry has negative consequences on the environment, such as releasing non-decomposable materials, or if it creates a cycle with the natural environment. If an industry produces non-decomposable materials and no cycle of resource transformation can be found, Michael wants to know what is the length of the longest chain of transformation from base resource to non-decomposable materials. Data format: Input The input file is called resources.in. The first line contains the number of resources N. The second line contains N names representing the names of each resource. Then on the next N lines: line i contains the name of the parent resource for the resource that has the index i. Output The output file is called resources.out. If a natural cycle has been detected, then the message Cycle detected! will be written on the first line of the output file. If there is no natural cycle detected, then the length of the longest chain of resource transformation will be written on the first line of the output file. Data limits: 1

Solve with C++: Problem 1: Resources Michael is an economist who researches

the impact of various industries on the natural environment. He wants to

Example 1: resources.in resources.out 5 4 Diesel CO2 Plastics Bottles Microplastics Petrol Diesel Petrol Plastics Bottles Petrol Diesel Plastics CO2 HIHI Bottles Microplastics Explanation Example 1: The longest chain of resource transformation has the length of 4: Petrol -> Plastics -> Bottles -> Microplastics Example 2: resources.in resources.out 4 Cycle detected! ABCD C B Base Base B D Explanation Example 2: Resources A, B and C form a natural cycle

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!