int main() { Graph g; Node node1(1), node2(2), node3(3), node4(4), node5(5), node6(6), node7(7), node8(8), node9(9); g.insert (Graph::value_type(node1, node3)); g.insert (Graph::value_type(node1, node4)); g.insert (Graph::value_type(node1, node5)); g.insert (Graph::value_type(node2, node6)); g.insert (Graph::value_type(node3, node6)); g.insert (Graph::value_type(node4, node7)); g.insert (Graph::value_type(node5, node7)); g.insert (Graph::value_type(node5, node8)); g.insert (Graph::value_type(node5, node9)); g.insert (Graph::value_type(node9, node5)); Graph::const_iterator it = g.begin(); while (it != g.end()) { std::pair<Graph::const_iterator, Graph::const_iterator> range = g.equal_range(it->first); std::cout << it->first << ": "; // print vertex for (; range.first != range.second; ++range.first) { std::cout << range.first->second << ", "; // print adjacent vertices } std::cout << std::endl; it = range.second; } }
int main() { Graph g; Node node1(1), node2(2), node3(3), node4(4), node5(5), node6(6), node7(7), node8(8), node9(9); g.insert (Graph::value_type(node1, node3)); g.insert (Graph::value_type(node1, node4)); g.insert (Graph::value_type(node1, node5)); g.insert (Graph::value_type(node2, node6)); g.insert (Graph::value_type(node3, node6)); g.insert (Graph::value_type(node4, node7)); g.insert (Graph::value_type(node5, node7)); g.insert (Graph::value_type(node5, node8)); g.insert (Graph::value_type(node5, node9)); g.insert (Graph::value_type(node9, node5)); Graph::key_compare cmp = g.key_comp(); Graph::const_iterator it = g.begin(), itEnd = g.end(), prev; while (it != itEnd) { std::cout << it->first << ": "; // print vertex do { std::cout << it->second << ", "; // print adjacent vertices prev = it++; } while (it != itEnd && !cmp(prev->first, it->first) && !cmp(it->first, prev->first)); std::cout << std::endl; } }
TEST(L124, normal) { std::shared_ptr<TreeNode> node1(new TreeNode(1)); std::shared_ptr<TreeNode> node2(new TreeNode(2)); std::shared_ptr<TreeNode> node3(new TreeNode(3)); Solution solution; ASSERT_EQ(1, solution.maxPathSum(node1.get())); node1->val = -3; ASSERT_EQ(-3, solution.maxPathSum(node1.get())); node1->val = 2; node2->val = -1; node1->left = node2.get(); node1->right = 0; ASSERT_EQ(2, solution.maxPathSum(node1.get())); node1->val = -2; node3->val = -3; node1->right = node3.get(); node1->left = 0; ASSERT_EQ(-2, solution.maxPathSum(node1.get())); node1->val = 2; node2->val = -1; node3->val = 2; node1->right = node3.get(); node1->left = node2.get(); ASSERT_EQ(4, solution.maxPathSum(node1.get())); node1->val = 5; node2->val = 4; node3->val = 8; std::shared_ptr<TreeNode> node4(new TreeNode(11)); std::shared_ptr<TreeNode> node5(new TreeNode(13)); std::shared_ptr<TreeNode> node6(new TreeNode(4)); std::shared_ptr<TreeNode> node7(new TreeNode(7)); std::shared_ptr<TreeNode> node8(new TreeNode(2)); std::shared_ptr<TreeNode> node9(new TreeNode(5)); std::shared_ptr<TreeNode> node10(new TreeNode(1)); node2->left = node4.get(); node3->left = node5.get(); node3->right = node6.get(); node4->left = node7.get(); node4->right = node8.get(); node6->left = node9.get(); node6->right = node10.get(); ASSERT_EQ(48, solution.maxPathSum(node1.get())); }
int main() { Solution s; { TreeNode node5(5); TreeNode node4(4); TreeNode node8(8); TreeNode node11(11); TreeNode node13(13); TreeNode node4a(4); TreeNode node7(7); TreeNode node2(2); TreeNode node1(1); node5.left = &node4; node5.right = &node8; node4.left = &node11; node8.left = &node13; node8.right = &node4; node11.left = &node7; node11.right = &node2; node4a.right = &node1; std::cout << s.hasPathSum(&node5, 22) << std::endl; } return 0; }
int main(void) { int c1 ; int i2 ; { c1 = 0; r1 = __VERIFIER_nondet_uchar(); id1 = __VERIFIER_nondet_char(); st1 = __VERIFIER_nondet_char(); send1 = __VERIFIER_nondet_char(); mode1 = __VERIFIER_nondet_bool(); id2 = __VERIFIER_nondet_char(); st2 = __VERIFIER_nondet_char(); send2 = __VERIFIER_nondet_char(); mode2 = __VERIFIER_nondet_bool(); id3 = __VERIFIER_nondet_char(); st3 = __VERIFIER_nondet_char(); send3 = __VERIFIER_nondet_char(); mode3 = __VERIFIER_nondet_bool(); id4 = __VERIFIER_nondet_char(); st4 = __VERIFIER_nondet_char(); send4 = __VERIFIER_nondet_char(); mode4 = __VERIFIER_nondet_bool(); id5 = __VERIFIER_nondet_char(); st5 = __VERIFIER_nondet_char(); send5 = __VERIFIER_nondet_char(); mode5 = __VERIFIER_nondet_bool(); id6 = __VERIFIER_nondet_char(); st6 = __VERIFIER_nondet_char(); send6 = __VERIFIER_nondet_char(); mode6 = __VERIFIER_nondet_bool(); id7 = __VERIFIER_nondet_char(); st7 = __VERIFIER_nondet_char(); send7 = __VERIFIER_nondet_char(); mode7 = __VERIFIER_nondet_bool(); i2 = init(); __VERIFIER_assume(i2); p1_old = nomsg; p1_new = nomsg; p2_old = nomsg; p2_new = nomsg; p3_old = nomsg; p3_new = nomsg; p4_old = nomsg; p4_new = nomsg; p5_old = nomsg; p5_new = nomsg; p6_old = nomsg; p6_new = nomsg; p7_old = nomsg; p7_new = nomsg; i2 = 0; while (1) { { node1(); node2(); node3(); node4(); node5(); node6(); node7(); p1_old = p1_new; p1_new = nomsg; p2_old = p2_new; p2_new = nomsg; p3_old = p3_new; p3_new = nomsg; p4_old = p4_new; p4_new = nomsg; p5_old = p5_new; p5_new = nomsg; p6_old = p6_new; p6_new = nomsg; p7_old = p7_new; p7_new = nomsg; c1 = check(); assert(c1); } } } return 0; }