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_p resent_time,_you_can_find_at_least_two_pastures_that_cannot_be_connected_by_any_sequence_of_cow_paths,_thus_partitioning_Farmer_John's_farm_ into_multiple_fields._
Farmer_John_would_like_add_a_single_a_cow_path_between_one_pair_of_pastures_using_the_constraints_below._
A_field's_`diameter'_is_defined_to_be_the_largest_distance_of_all_the_shortest_walks_between_any_pair_of_pastures_in_the_field._Consider_the _field_below_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.07106,_since_the_longest_of_the_set_of_shortest_paths_between_pairs_of_pastures_is_the_path _from_A_to_E_(which_includes_the_point_set_{A,B,E})._No_other_pair_of_pastures_in_this_field_is_farther_apart_when_connected_by_an_optimal_s equence_of_cow_paths._
Suppose_another_field_on_the_same_plane_is_connected_by_cow_paths_as_follows:_
_________________________*F_30,15
_________________________/_
________________________/__
______________________/____
____________________/______
___________________*------_
___________________G______H
___________________25,10___30,10
In_the_scenario_of_just_two_fields_on_his_farm,_Farmer_John_would_add_a_cow_path_between_a_point_in_each_of_these_two_fields_(namely_point_s ets_{A,B,C,D,E}_and_{F,G,H})_so_that_the_joined_set_of_pastures_{A,B,C,D,E,F,G,H}_has_the_smallest_possible_diameter._
Note_that_cow_paths_do_not_connect_just_because_they_cross_each_other;_they_only_connect_at_listed_points._
The_input_contains_the_pastures,_their_locations,_and_a_symmetric_"adjacency"_matrix_that_tells_whether_pastures_are_connected_by_cow_paths. _Pastures_are_not_considered_to_be_connected_to_themselves._Here's_one_annotated_adjacency_list_for_the_pasture_{A,B,C,D,E,F,G,H}_as_shown_a bove:_
________________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_alphabetical_to_show_the_point_connection s._The_input_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_field_has_the_smallest_possible_diameter_of _any_possible_pair_of_connected_pastures._Output_that_smallest_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)_that_represent_the_adjacency_matrix_as_described_above,_where_the_rows'_and_columns'_indice s_are_in_order_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_diameter_of_the_newly_joined_pastures._Print_the_answer_to_exactly_six_decimal_places._Do_not_ perform_any_special_rounding_on_your_output._
SAMPLE_OUTPUT_(file_cowtour.out)
22.071068
Էջանիշներ