The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 6 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
lectric town has only N electricity powerhouses. All these powerhouses do is generate power and transmit it to other powerhouses.
Also there are unidirectional power cables between these powerhouses. These cables go in one direction from powerhouse X to powerhouse Y.
Â
Each of these cables also have a maximum integral capacity, which is an upper limit on the amount of power they can transfer. These capacities will be given.
Â
Now, say a powerhouse receives R amount of power from other powerhouses, and gives out a total of S amount of power out to other powerhouses.
Further, suppose it generates G amount of power. Then the amount of power going out of the powerhouse should be the sum of the power it receives, and the power it generates. That is, S = R + G.
Since electric town is a very advanced town, G could be anything (non negative).
Â
You are Jaylal, a mafia in the town, and you have a special superconducting (again unidirectional) cable. This cable has infinite capacity, and can hence transfer any amount of electricity.
You can connect this cable between from powerhouse A to powerhouse B, and since you control this cable, you will obtain the electricity that flows through this cable. You add this cable to the network, and the powerhouses continue to transmit power
in the same fashion as before, without noticing that there is another cable.
Â
Of course you want to be able to get the maximum electricity. What is the maximum electricity that could be travelling in this cable?
You have to answer this question T times, for T different pairs of powerhouses A, B that you connect this cable in. All these answers have to be independently outputted. (see sample)
Â
Â
First line of the input contains two space separated integers N and M
denoting the number of powerhouses and number of cables respectively.
Â
For next M lines, each line contains three sapce separated integers U V W, denoting that there is a cable directed from powerhouse U to powerhouse V with electric capacity W.
Â
A single line containing an integer T : the number of different layouts of the superconducting cable you are going to try out.
T lines follow, each containing two integers A and B denoting that the cable is connected from B to A.
Â
Â
Output T lines each containing a single integer corresponding to the maximum electricity you can hijack in that case case.
Â
Â
Â
Input: 3 2 1 2 5 2 3 3 2 1 3 1 2 Output: 3 5
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll