A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d2/de9/heavy__light__decomposition_8cpp.html below:

TheAlgorithms/C++: range_queries/heavy_light_decomposition.cpp File Reference

555 {

556 std::cout << "Test 2:\n";

557

558

559 int n = 10;

560 std::vector<int64_t> node_values = {1, 8, 6, 8, 6, 2, 9, 2, 3, 2};

561 std::vector<std::vector<int>> edges = {{10, 5}, {6, 2}, {10, 7},

562 {5, 2}, {3, 9}, {8, 3},

563 {1, 4}, {6, 4}, {8, 7}};

564 std::vector<std::vector<int>> queries = {

565 {2, 1, 10}, {2, 1, 6}, {1, 3, 4}, {2, 1, 9}, {1, 5, 3},

566 {1, 7, 8}, {2, 1, 4}, {2, 1, 8}, {1, 1, 4}, {1, 2, 7}};

567 std::vector<int> expected_result = {27, 11, 45, 9, 34};

568 std::vector<int> code_result;

569

571 hld.set_node_val(node_values);

572 for (int i = 0; i < n - 1; i++) {

573 int u = edges[i][0], v = edges[i][1];

574 hld.add_edge(u - 1, v - 1);

575 }

576 hld.init();

577 for (const auto &q : queries) {

578 int type = q[0];

579 if (type == 1) {

580 int p = q[1], x = q[2];

581 hld.update(p - 1, x);

582 } else if (type == 2) {

583 int a = q[1], b = q[2];

584 code_result.push_back(hld.query(a - 1, b - 1));

585 } else {

586 continue;

587 }

588 }

589 for (int i = 0; i < static_cast<int>(expected_result.size()); i++) {

590 assert(expected_result[i] == code_result[i]);

591 }

592 std::cout << "\nTest2 passed!\n";

593}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4