fork(1) download
  1. #include <chrono>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. struct Route
  7. {
  8. int dest;
  9. int cost;
  10. };
  11.  
  12. using Node = std::vector<Route>;
  13.  
  14. std::vector<char> visited;
  15. std::vector<Node> nodes;
  16.  
  17. static
  18. int GetLongestPath(int index)
  19. {
  20. int max = 0;
  21. visited[index] = true;
  22.  
  23. for (auto neighbour : nodes[index])
  24. {
  25. if (!visited[neighbour.dest])
  26. {
  27. auto dist = neighbour.cost + GetLongestPath(neighbour.dest);
  28. max = std::max(max, dist);
  29. }
  30. }
  31.  
  32. visited[index] = false;
  33. return max;
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39. std::ifstream in("agraph");
  40.  
  41. int num_nodes;
  42. in >> num_nodes;
  43. nodes.resize(num_nodes);
  44. visited.resize(num_nodes);
  45.  
  46. int index;
  47. int neighbour;
  48. int cost;
  49. while (in >> index >> neighbour >> cost)
  50. {
  51. nodes[index].push_back({neighbour, cost});
  52. }
  53.  
  54. auto start = std::chrono::steady_clock::now();
  55. auto len = GetLongestPath(0);
  56. auto stop = std::chrono::steady_clock::now();
  57. auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
  58. std::cout << len << " LANGUAGE C++/" << COMPILER << " " << ms.count() << "\n";
  59. }
Compilation error #stdin compilation error #stdout 0s 3472KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:58:45: error: ‘COMPILER’ was not declared in this scope
     std::cout << len << " LANGUAGE C++/" << COMPILER << " " << ms.count() << "\n";
                                             ^
stdout
Standard output is empty