True. The problem is SPT_Dijkstra in Graph is sometimes wrong.
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Syntax::Construct qw{ // }; use Graph; my %graph; my $first; # Handle the sample data where there are sometimes less than 4 neighbo +urs. while (<DATA>) { my ($node, @neighbours) = split; $first //= $node; my $distance = 1; for my $neighbour (@neighbours) { if (not exists $graph{$node}{$neighbour} or $graph{$node}{$neighbour} < $distance) { $_ = $distance for $graph{$node}{$neighbour}, $graph{$neighbour}{$node}; } $distance++; } } my $g = 'Graph::Undirected'->new; for my $u (keys %graph) { for my $v (keys %{ $graph{$u} }) { $g->add_weighted_edge($u, $v, $graph{$u}{$v}); } } my $dij = $g->SPT_Dijkstra($first); my %weights = ($first => 0); $weights{$_} //= $dij->get_vertex_attribute($_, 'weight') for keys %gr +aph; say join ' ', sort { $weights{$a} <=> $weights{$b} } keys %weights; __DATA__ O1 O3 O5 O11 O73 O2 O72 O54 O12 O7 O3 O1 O6 O5 O12 O5 O1 O3 O6 O3 O7 O2 O11 O1 O12 O2 O3 O54 O2 O72 O2 O73 O1
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re^2: Sorting problem by choroba
in thread Sorting problem by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.