Problem

(Financial tsunami) Banks loan money to each other. In tough economic times, if a bank goe...

(Financial tsunami) Banks loan money to each other. In tough economic times, if a bank goes bankrupt, it may not be able to pay back the loan. A bank’s total asset is its current balance plus its loans to other banks. Figure is a diagram that shows five banks. The banks’ current balances are 25 , 125 , 175 , 75 , and 181 million dollars, respectively. The directed edge from node 1 to node 2 indicates that bank 1 loans 40 million dollars to bank 2.

Figure 8.7 Banks loan money to each other.

If a bank’s total asset is under a certain limit, the bank is unsafe. If a bank is unsafe, the money it borrowed cannot be returned to the lender, and the lender cannot count the loan in its total asset. Consequently, the lender may also be unsafe, if its total asset is under the limit. Write a program to find all unsafe banks. Your program reads the input as follows. It first reads two integers n and limit , where n indicates the number of banks and limit is the minimum asset for keeping a bank safe. It then reads n lines that describe the information for n banks with id from 0 to n-1. The first number in the line is the bank’s balance, the second number indicates the number of banks that borrowed money from the bank, and the rest are pairs of two numbers. Each pair describes a borrower. The first number in the pair is the borrower’s id and the second is the amount borrowed. Assume that the maximum number of the banks is 100. For example, the input for the five banks in Figure is as follows (the limit is 201):

The total asset of bank 3 is (75 + 125), which is under 201. So bank 3 is unsafe. After bank 3 becomes unsafe, the total asset of bank 1 becomes 125 + 40. So bank 1 is also unsafe. The output of the program should be

Unsafe banks are 3 1

(Hint : Use a two-dimensional array borrowers to represent loans. 1oan[i] [j] indicates the loan that bank i loans to bank j. Once bank j becomes unsafe, 1oan[i][j] should be set to 0.)

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT