Cow_Tours
Farmer_John_has_a_number_of_pastures_on_his_farm._ Cow_paths_connect_some_pastures_with_certain_other _pastures,_forming_a_field._But,at_the_present_tim e,_you_can_find_at_least_two_pastures_that_cannot_ be_connected_by_any_sequence_of_cow_paths,_thus_pa rtitioning_Farmer_John's_farm_into_multiple_fields ._
Farmer_John_would_like_add_a_single_a_cow_path_bet ween_one_pair_of_pastures_using_the_constraints_be low._
A_field's_`diameter'_is_defined_to_be_the_largest_ distance_of_all_the_shortest_walks_between_any_pai r_of_pastures_in_the_field._Consider_the_field_bel ow_with_five_pastures,_located_at_the_points_shown ,_and_cow_paths_marked_by_lines:_
________________15,15___20,15
__________________D_______E
__________________*-------*
__________________|______/|
__________________|____/__|
__________________|__/____|
__________________|/______|
_________*--------*-------*
_________A________B_______C
_________10,10___15,10___20,10
The_`diameter'_of_this_field_is_approximately_12.0 7106,_since_the_longest_of_the_set_of_shortest_pat hs_between_pairs_of_pastures_is_the_path_from_A_to _E_(which_includes_the_point_set_{A,B,E})._No_othe r_pair_of_pastures_in_this_field_is_farther_apart_ when_connected_by_an_optimal_sequence_of_cow_paths ._
Suppose_another_field_on_the_same_plane_is_connect ed_by_cow_paths_as_follows:_
_________________________*F_30,15
_________________________/_
________________________/__
______________________/____
____________________/______
___________________*------_
___________________G______H
___________________25,10___30,10
In_the_scenario_of_just_two_fields_on_his_farm,_Fa rmer_John_would_add_a_cow_path_between_a_point_in_ each_of_these_two_fields_(namely_point_sets_{A,B,C ,D,E}_and_{F,G,H})_so_that_the_joined_set_of_pastu res_{A,B,C,D,E,F,G,H}_has_the_smallest_possible_di ameter._
Note_that_cow_paths_do_not_connect_just_because_th ey_cross_each_other;_they_only_connect_at_listed_p oints._
The_input_contains_the_pastures,_their_locations,_ and_a_symmetric_"adjacency"_matrix_that_tells_whet her_pastures_are_connected_by_cow_paths._Pastures_ are_not_considered_to_be_connected_to_themselves._ Here's_one_annotated_adjacency_list_for_the_pastur e_{A,B,C,D,E,F,G,H}_as_shown_above:_
________________A_B_C_D_E_F_G_H
______________A_0_1_0_0_0_0_0_0
______________B_1_0_1_1_1_0_0_0
______________C_0_1_0_0_1_0_0_0
______________D_0_1_0_0_1_0_0_0
______________E_0_1_1_1_0_0_0_0
______________F_0_0_0_0_0_0_1_0
______________G_0_0_0_0_0_1_0_1
______________H_0_0_0_0_0_0_1_0
Other_equivalent_adjacency_lists_might_permute_the _rows_and_columns_by_using_some_order_other_than_a lphabetical_to_show_the_point_connections._The_inp ut_data_contains_no_names_for_the_points._
The_input_will_contain_at_least_two_pastures_that_ are_not_connected_by_any_sequence_of_cow_paths._
Find_a_way_to_connect_exactly_two_pastures_in_the_ input_with_a_cow_path_so_that_the_new_combined_fie ld_has_the_smallest_possible_diameter_of_any_possi ble_pair_of_connected_pastures._Output_that_smalle st_possible_diameter._
PROGRAM_NAME:_cowtour
INPUT_FORMAT
Line_1:__An_integer,_N_1_<=_N_<=_150),_the_number_ of_pastures__
Line_2-N+1:__Two_integers,_X_and_Y_(0_<=_X_,Y<=_100000),_ that_denote_that_X,Y_grid_location_of_the_pastures ;_all_input_pastures_are_unique.__
Line_N+2-2*N+1:__lines,_each_containing_N_digits_(0_or_1)_t hat_represent_the_adjacency_matrix_as_described_ab ove,_where_the_rows'_and_columns'_indices_are_in_o rder_of_the_points_just_listed.__
SAMPLE_INPUT_(file_cowtour.in)_
8
10_10
15_10
20_10
15_15
20_15
30_15
25_10
30_10
01000000
10111000
01001000
01001000
01110000
00000010
00000101
00000010
OUTPUT_FORMAT
The_output_consists_of_a_single_line_with_the_diam eter_of_the_newly_joined_pastures._Print_the_answe r_to_exactly_six_decimal_places._Do_not_perform_an y_special_rounding_on_your_output._
SAMPLE_OUTPUT_(file_cowtour.out)
22.071068
Էջանիշներ