Exemplo n.º 1
0
int main() {
  while (true) {
    int N, M;
    scanf("%d %d", &N, &M);
    if (N == 0 && M == 0)
      break;

    int S, D;
    scanf("%d %d", &S, &D);

    Graph<int> G(N);
    for (int m = 0; m < M; ++m) {
      int u, v, p;
      scanf("%d %d %d", &u, &v, &p);
      G.add_edge(u, v, p);
    }

    Dijkstra<int> di(G, S);
    std::set<int> short_edges;
    for (const auto& e : di.get_shortest_edges(D))
      short_edges.insert(e.index);

    Graph<int> G2(N);
    for (int u = 0; u < N; ++u) {
      for (const auto& e : G.adj(u)) {
        if (short_edges.find(e.index) == short_edges.end())
          G2.add_edge(e.from, e.to, e.cost);
      }
    }

    Dijkstra<int> di2(G2, S);
    int res = di2.has_path(D) ? di2.get_cost(D) : -1;
    printf("%d\n", res);
  }
}
Exemplo n.º 2
0
TEST_F(ItemDataTest, CopyCtor)
{
  emptyItem.SetTitle(_T("title"));
  emptyItem.SetPassword(_T("password!"));

  CItemData di2(emptyItem);
  EXPECT_TRUE(emptyItem == di2);
}
Exemplo n.º 3
0
// test_function_countUnique
// Test suite for function template countUnique
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_function_countUnique(Tester & t)
{
    std::cout << "Test Suite: function template countUnique (Exercise C)"
              << std::endl;

    std::deque<int> di {
        1, 1, 2, 1, 2, 2, 3, -1, -1, -1, 5, 3, 3, 3, 2, 2, 1, 1, 1
    };
    std::deque<int> dic;

    // Check return type of countUnique
    dic = di;
    t.test(TypeCheck<std::size_t>::check(
               countUnique(dic.begin(), dic.end())),
           "countUnique: return type");

    dic = di;
    t.test(countUnique(dic.rbegin(), dic.rbegin()) == 0,
        "Empty range");

    dic = di;
    t.test(countUnique(dic.rbegin()+3, dic.rbegin()+4) == 1,
        "Size 1");

    dic = di;
    t.test(countUnique(dic.rbegin()+3, dic.rbegin()+5) == 1,
        "Size 2, equal integers");

    dic = di;
    t.test(countUnique(dic.rbegin()+4, dic.rbegin()+6) == 2,
        "Size 2, distinct integers");

    dic = di;
    t.test(countUnique(dic.rbegin()+9, dic.rbegin()+12) == 1,
        "Size 3, equal integers");

    dic = di;
    t.test(countUnique(dic.rbegin()+7, dic.rbegin()+10) == 3,
        "Size 3, distinct integers");

    dic = di;
    t.test(countUnique(dic.rbegin()+8, dic.rbegin()+11) == 2,
        "Size 3, two values");

    dic = di;
    t.test(countUnique(dic.rbegin()+5, dic.rbegin()+13) == 3,
        "Longer test #2");

    dic = di;
    t.test(countUnique(dic.rbegin()+3, dic.rbegin()+15) == 4,
        "Longer test #2");

    dic = di;
    t.test(countUnique(dic.rbegin(), dic.rend()) == 5,
        "Longer test #3");

    {
    std::deque<int> di2(100000, 3);
    t.test(countUnique(di2.rbegin(), di2.rend()) == 1,
        "Very long test #1");
    }

    {
    std::deque<int> di2(100000, 4);
    di2[40000] = 3;
    t.test(countUnique(di2.rbegin(), di2.rend()) == 2,
        "Very long test #2");
    }

    {
    std::deque<int> di2(100000, 4);
    for (size_t i = 0; i != 100000; i += 2)
        di2[i] = 3;
    t.test(countUnique(di2.rbegin(), di2.rend()) == 2,
        "Very long test #3");
    }

    {
    std::vector<std::string> vs { "abc", "abc" };
    t.test(countUnique(vs.begin(), vs.end()) == 1,
        "Strings, equal");
    }

    {
    std::vector<std::string> vs { "abc", "def" };
    t.test(countUnique(vs.begin(), vs.end()) == 2,
        "Strings, distinct");
    }
}