- reari Resul-t :: Faf se; endi end,: procedure var -FntanAr F\all-r .i v, Augment.Fl-ow ; Tnf6^6r , begin v ::' n,' h^l +uerLd - h^ t[a^v, rePeat i :: trace [v] ; if elil.c - elil.f < Delta then De1ta :: elil.c - elil.f; v :: elil;x; until.v = 1; v | - ll, rePeat i :: trace [v] ; < etil.c) then Inc (e Ii] , De1ta) ; [-i] f, Detta) ; v := e lil xl unlil v = 1; Fl-owValue :: Fl-owValue + Del-ta; end; procedure PiintResult, f Dec (e , i: Integer; f o : TextFil-e; ,begin AssignFile (fo, OutputFiJ-e) Rewrite (fo) ; ; Ery Writel,n (fo, Fl_owValue.) ; fori:=ltomdo with elil if, (tnacelxl = 0) xor (traceIy] : 0) then Write (fo, i, ' ') ; fin'al1y : CLoseFife (fo) end; ; end,' begin Enter: t Init.ZeroFlow; while Findpath AugmentFlow; ' PrintResult; end :1.49 Xdy dwng thuqt todn vd cdi ddt chuong,trinh Ddy le bei to6n ngdoi dua thu Trung Hoa trucrng hqp d6 thi c6 huong (Directed Chinese postman problem) Gqi X ln tf,p dinh "thira": Nhirng dinh c6 s6 cung di vdo nhieu hcrn s6 cung di'ra, mfc thria cia mQt dinh u ld deg-( u) deg+ (v) - Gqi I/ ld tpp dinh "thi6u": Nhirng dinh c6 s6 cung di nhiAu hon sti cung \ di vdo, muc thi6u cria mQt dinh u ld deg+(u) deg*(u) 168 Tim m6t bQ duong di fu X sang I' thoa r,ndn: -:"r M6ijduong'cli xudt ph6t tu mQt dinh thua vd k6tthric tpi mQt din[ thi6u; M6i dinh thua c6 sti ducrng di xu6t ph6t tu n6 dring bing mric thua; vt6i dinh thi6i c6 s6 duong di ktit thfc tai n6 dring bing mric thi6u; -l TOng d0 ddi c6c dudng di ld ngdn nhat c6 th6, DC tim bQ duong di ndy c6 thO su dgng thuat todn ghdp cflp c6 trgng s6 ho[c luOng chi phi cgc ti€u Chwong rrinh {$MODE OBJFPC} Di rectedChrnesePostman program ; consE InputFile = 'DCPP trNP' ; OutputFile = ' DCPP OUT' ; maxN = Round(1E3); maxM = Round (1E4 ) ; maxW = Round(1E5); m:xD=maxN*maxW, ^ *:' " tyPe TEdge = reqord u/ v: Integeir; c, f , w: Integer,' - link: Integer,' end; ' Tlleap = recor{ ' items, pos: array[1 maxN] of Integer; nftems: fnteger; end,' var fi, LL I fo : TextFife r n f a^a ; r e: array[-maxM maxM] of TEdge; head: array[1 .maxN] o.f 'f nteger,' p: 'array [1 maxN] 'of Integer; d: arl?y[1 maxN] of Integer; excess: array[1 .maxN] of Integer; 169 trace: array[ maxN] of Ihteger; z array[1 maxN] of Integer; Tnl-a^6r heap: THeap; res: Int64 i procedure Enter,' var i ' Tn F6-ar rl.LvYvr begin (fi, n, m) ; {or.i::1to.mdo Readln(fi, eIi].u, for i :: l- to m Readln elil.w); elil.v, begin e[-i].u :: e[1].v; eI-il.v := elil.u; t elil.c := mi e[-i].c := 0; etil.f := 0; :: 0; e[-i].f := -etil.w; e[-i].w ' 'end; Fif l-DWo::d(head[1], n, 0) i ',f,or i :: -m tg m ifi0then with elil begin ' Iink := headlul,' headlul := i; end; endi function cf(const e: TEdge): Integer; inlinei begin with e Resuft := c - f;: end,' function wp(const e: TEdge): Integer; inline; begin with e Result := w + FluJ - ptvl t70 i endi procedure tnit; : r ver : ' i :' rntegey';' l 'i beain Fil1DWor$(excess[1], n, for + :=.1 to m , with elil O); ' Deg:.n : '\ Ded(excess [u] ) ; r_nc (excess lvl ); end, r FillDWord (p t lr, n, ) ;' end; ^ bi1 kstrarnit ( stqrt : :;fr9""" FiIlDWord(d.[1], n; maxD) ii.tstartl : = 01 with - heap, '' FiIlDWord (bos [1 J ,, n, nlte$s := Li Oegin ; Tnl-aaar\ : ' t '., ), ; I Pos[startl ':! 1; endt en6; :1 fuocirion Extract: Y+r r Tnl-aaar rrrevYv! t l i t Tnl-ariar, gvYv!, temp: ': fnteqer; beaia -iith,heap 't^ , begin Result :1 items '' l [L]l ; temp := ,items Inltems], Dec-( nltems) t r = Lt1 r€peat { c t: i *.2; I n (c < nltem5) and (dlitems Ic]l > dlitems Ic + then I.nc (c) i if ].1I ) : Break; items [.r] :: items Ic] pos Iitems IrJ ] 2: r; ! - ,' r U, until False; itemsIr] i= tempq Poslt.ernPl := r; glnd; end,' function Update (v, dv: Integer) : Boolean; var r Lt i Tnl_6d6r , begin ? Result := dlvl > dv; if not Result then Exit; otvl := crv; with heap begin ifc=0then begin Inc (nltems ) , c := nltems; : end; rePeat r r :: c d,Lv 2; if (r : 0) or, (dlitems trl I o).and UPdate(v,dluPoPl + wP(elil)) then trace[v] := i; i := ]ink; 'end; until False; / /Uodate price function for'1 := 1'to nz rnc (p tz Iil L dlz til I.- dlResultl.) ; end,' procedure AugmentFf var ow ( s', t : Integer:) ; L, -v, De]ta: Integet; begin if excessIs] < -excessIt] then Del-ta :: excessIs] else Delta :: -excessIt]; v := t; repead i := trace [v] ; t73 rnn /a f i l !tr \v LrJ Delta) ; Dec(e.[-i] f, Delt.a) ; v := elil.u; until v = s; Dec (excess Is], Del-ta),' Inc (excess It] , Detta) ; eod; , , , procedure Succes s iveShortes tPaths,' var sr L, ii Integer; begin for s :: to n while excessls] > begin t Di j kstra (s )-; AugmentFlow (s, t) ; : = end; rac = n.' for i :: to m res :: res + e[i].w; fori:=-mtomdo if (i 0) and (etil.f > 0) then res :: res + Int64 (e til f) * e Ii] w; end; begin AssignFile (fi, Le ; ( Reset (fi) ; ASS]-gnr']1e Par^rrifa/fn\ I InputFile) (ro, uu.EpuEf rte) ; ( t \!v/ try !fk hfr uv!^P t Init; SuccessiveShortest.Pat.hs; Write (f o, res ) ,' finally 1-lneoE'i'la/fi.); f f v \!4/ CloseFil-e (f o) end; end ' t74 t ; , ' MUCLUC • • Loi n6i d�u BAI T�P J Chuyen d� KIEU DU LIBU TRl U TVQNG v A cAu TRUC DU' uBu Bai t�p chuyeu-d� Bai t�p b6 ·sung 14 Chuyen d� DO THl Bai t�p chuyen d� 23 Bai t�p b6 sung_ 37 HU'O'NG DAN - GIAI BAI T�p Chuyen d� 44 ChuY,en d� 116 175 vuoNc M|FN KrM GUdNC cH{r ruoNs auocrd Gtfi rHtEu BQ sAcH TATLTFU CHUYEN TrN HgC DANH CHo HgC S|NH pHo THoNG BVn dlc co thd mua sdch tqi cdc Cong ty Sdch - Thi6t b! trudng hgc cdc hodc cthc cta hdng sdtch crta Nhd xudt bAn Gi6o dyc ViQt Nam : - T4i TP Hi N0i : - Tai TP 0d Ning - - T4i phndng 45 Phd Vqng ;187 ,187C Giing VO ;232fAy Son ; 25 Hin Thuy0n; 51 Lo D0c ; 45 Hdng Chudi ; NgO 385 Hodng Oudc Vi0t; : TaiTP ttd Ctri lvtintr : -TaiTP CO'nTho Ctia : 17 T2 - 17T3 Trung Hda - Nh0n Chinh ; Tda nhd HESCO Vin 0u6n - Hi D0ng 78 Pasteur ; 45 L0 Ldi ;223 L0 Dinh Lf 261 C LC Ouang Dinh, 0u0n Binh Thanh ; 231 Nguy6n Vin Cil, 0u0n b ; 23 Dinh Tien Hoing, Phtldng Da Kao, 0u0n , TP Hd ChiMinh 162DDudng3 thAng2,PhudngXudn Kh6nh, 0u0n Ninh Kidu Website b6n hing trqc tuyOn : www.sach24.vn lsBN 978-604-0-082 I 6-9 www.nxbgd.vn ,ll[[Jil[tillluulil Giti:31.000d ... th6 tinh dugc thoi gian O(lEl) Gq'i y;Chf i ring c6c trgng sd w{e) e {0,1}' 27 c) Hdy chi ring v6i moi i= 2, 3, ,2 wrG) = 2. wr-r(e) hoflc wr@),= 2. wi-r(e) + f Tt 7.1 d6 chring minh ring: 2. 6i-r(s,... hdnh trinh tirn duoc Vi du: DCPP.INP DCPP,OUT 69 L44 24 2 28 3r2 326 341 4 52 463 533 631 Gidi thich; Hdnh trinh cAn tim ld I -+ -+ 6-+3 - +2 -+ -> -+3 -+ -+ -+3 -+ I nen thay r.,.' 4Ieu dia ,'l... tQp Input va Output dwqc ghi cach ft nhd:t m ddu cach Vf du: SEAPORTS.INP 25 03 35 o2 25 14 SEAPORTS.OUT LL22O 6. 12 Thdng Bdm vd Phir Ong rg la ii rc o u a Bom thing Phri Ong mQt cuQc tl6nh