the kingdom Olympia consist N city M bidirectional road each road connect exactly city city connect road also possible road connect city make loopall road constantly plunder bandit after bandit bore waste time road robbery suggest king Olympia pay accord offer bandit want gift consist gold silver coin Offer contain list restriction road know gi small gold si small silver coin gift stop robbery road that gift contain gold b silver coin bandit stop robbery road gia sibunfortunately kingdom treasury do not contain gold silver coin olympian tugrik the cost gold coin tugrik g cost silver coin tugrik S King wants send bandit gift city exist safe path your task find minimal cost olympian tugrik require gift