Asyouknow,anundirectedconnectedgraphwithnnodesandn - 1edgesiscalledatree.Youaregivenanintegerdandatreeconsistingofnnodes.Eachnodeihasavalueaiassociatedwithit.WecallasetSoftreenodesvalidiffollowingconditionsaresatisfied:Sisnon-empty.Sisconnected.Inotherwords,ifnodesuandvareinS,thenallnodeslyingonthesimplepathbetweenuandvshouldalsobepresentedinS..Yourtaskistocountthenumberofvalidsets.S...
ProblemDescriptionAschoolboughtthefirstcomputersometimeago(sothiscomputer'sidis1).DuringtherecentyearstheschoolboughtN-1newcomputers.Eachnewcomputerwasconnectedtooneofsettledearlier.ManagersofschoolareanxiousaboutslowfunctioningofthenetandwanttoknowthemaximumdistanceSiforwhichi-thcomputerneedstosendsignal(i.e.lengthofcabletothemostdistantcomputer).Youneedtoprovidethisinformation.Hint:the...
AfteryouhadhelpedFedortofindfriendsinthe«CallofSoldiers3»game,hestoppedstudyingcompletely.Today,theEnglishteachertoldhimtoprepareanessay.Fedordidn'twanttopreparetheessay,soheaskedAlexforhelp.AlexcametohelpandwrotetheessayforFedor.ButFedordidn'tliketheessayatall.NowFedorisgoingtochangetheessayusingthesynonymdictionaryoftheEnglishlanguage.Fedordoesnotwanttochangethemeaningoftheessa...
Applemanhasatreewith n vertices.Someofthevertices(atleastone)arecoloredblackandotherverticesarecoloredwhite.Considerasetconsistingof k (0 ≤ k < n) edgesofAppleman'stree.IfApplemandeletestheseedgesfromthetree,thenitwillsplitinto (k + 1) parts.Note,thateachpartwillbeatreewithcoloredvertices.NowApplemanwonders,whatisthenumberofsetssplittingthetreeinsuchawaythateachresultingp...
近期评论