Computer Science Canada

DWITE 2006 January #5

Author:  A.J [ Mon Jan 28, 2008 12:05 am ]
Post subject:  DWITE 2006 January #5

In the question 'Distance between cities', I think the second sample test case is faulty.
i got 8 instead of 7.

Author:  zylum [ Mon Jan 28, 2008 12:59 am ]
Post subject:  RE:DWITE 2006 January #5

I get 7 with my solution...

code:
var adj : array 0 .. 12, 0 .. 12 of int
for i : 0 .. 12
    for j : 0 .. 12
        adj (i, j) := 100000
    end for
end for

var fi, fo : int
open : fi, "DATA51.txt", get
open : fo, "OUT51.txt", put

var N, d : int
var line : string

get : fi, N

for i : 1 .. N
    get : fi, line
    get : fi, d
    adj (ord (line (1)) - 65, ord (line (2)) - 65) := d
    adj (ord (line (2)) - 65, ord (line (1)) - 65) := d
end for

for k : 0 .. 12
    for i : 0 .. 12
        for j : 0 .. 12
            adj (i, j) := min (adj (i, j), adj (i, k) + adj (k, j))
        end for
    end for
end for

for : 1 .. 5
    get : fi, line
    put : fo, adj (ord (line (1)) - 65, ord (line (2)) - 65)
end for

close (fi)
close (fo)


F->E->C->B gives 7

Author:  A.J [ Mon Jan 28, 2008 3:28 pm ]
Post subject:  Re: DWITE 2006 January #5

I did it using your method too, but when i tried to use Dijkstra's algorithm (and a weirder approach) it didn't work.
I guess i should stick with my easier method.
Thanks anyways.


: