program name components; description "Zjisti z kolika komponent se zadany graf sklada"; define KNode extends Node attributes int group; ; KEdge extends Edge (KNode); KGraph extends Graph (KEdge); var KGraph graph; KNodes node, nodes; KNodes source, destination; KEdges edge, edges; int i; procedure main(); do writeln(get_error_text(graph load_from_file("D:\\Projects\\Rocnikovy projekt\\070420\\graphs\\Komponenty1.dat"))); nodes := graph get_nodes(); i := 0; for each node from nodes do i := i + 1; node set_group(i); enddo // kazde skupine prideli specificke cislo, které mají všechny prvky komponenty edges := graph get_edges(); for each edge from edges do source := edge get_nodes_source(); destination := edge get_nodes_destination(); if source get_group_value() != destination get_group_value() then do source := nodes get_group_equal(source get_group_value()); destination := nodes get_group_equal(destination get_group_value()); if source get_size() < destination get_size() then source set_group(destination get_group_value()); else destination set_group(source get_group_value()); i := i - 1; enddo enddo terminate("Zadany graf se sklada ze " + int_to_string(i) + " komponent."); enddo