#! perl -slw use strict; my $n = <>; my %pairings; push( @{ $pairings{ $_->[0] } }, $_->[1] ), push( @{ $pairings{ $_->[1] } }, $_->[0] ), while @{ $_ = [ split ' ', <> ] }; my $total = 0; my @guests; while( $total < $n ) { my $next = ( sort{ @{ $pairings{ $b } } <=> @{ $pairings{ $a } } } keys %pairings )[ 0 ]; push @guests, $next; $total += @{ $pairings{ $next } }; delete $pairings{ $_ } for @{ delete $pairings{ $next } }; } print scalar @guests; print for @guests;