in reply to what is wrong with my Dijkstram algorithm?

You are not using strict and warnings for starters. Next:

my $root= <>;
You should chomp it, otherwise $root will contain newline in the end.
my %graph= %graph;
Oh, really?
$dist{$n2} = $dist{$n} + $graph{$n1}{$n2};
And this is why you should use strict, note $dist{$n}, shouldn't it be $dist{$n1}?