Advertisement
SpaceCreator

v

Mar 19th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. typedef std::vector<int> v_int;
  6.  
  7. struct Road {
  8.     int to;
  9.     int in_way_time;
  10.  
  11.     explicit Road(int t = 0, int w = 0) {
  12.         to = t;
  13.         in_way_time = w;
  14.     }
  15. };
  16.  
  17. typedef std::vector<Road> v_road;
  18.  
  19. typedef std::queue<int> q_int;
  20.  
  21. struct CListGraph {
  22.     explicit CListGraph(size_t num);
  23.  
  24.     void add_edge(int from, int to, int weight);
  25.  
  26.     size_t vertices_count() const;
  27.  
  28.     void get_next_vertices(int vertex, v_road &vertices) const;
  29.  
  30. private:
  31.     std::vector<v_road> vertices_list;
  32.  
  33.     void add_vertexes(int necessary_num);
  34. };
  35.  
  36. struct For_A_Round {
  37.     For_A_Round(size_t vertices_num, CListGraph *graph) {
  38.         vertices_color.resize(vertices_num, false);
  39.         my_graph = graph;
  40.         vertices_dist.resize(vertices_num, vertices_num);
  41.     }
  42.  
  43.     std::queue<q_int> queue_of_queues;
  44.     std::vector<bool> vertices_color;
  45.     v_int vertices_dist;
  46.     CListGraph *my_graph;
  47.  
  48.     void get_next_vertices(int vertex, v_road &vertices) const;
  49. };
  50.  
  51. void build_graph(CListGraph *my_graph, int num_of_edges) {
  52.     int from = 0;
  53.     int to = 0;
  54.     int weight = 1;
  55.     for (int i = 0; i < num_of_edges; ++ i) {
  56.         std::cin >> from >> to >> weight;
  57.         if (from != to) {
  58.             my_graph->add_edge(to, from, weight);
  59.         }
  60.     }
  61. }
  62.  
  63. void round(For_A_Round *my_round, int currrent_dist, int current_vertex) {
  64.     v_road =
  65. }
  66.  
  67. void find_the_shortest_way(CListGraph *my_graph, int from, int to) {
  68.     For_A_Round my_round(my_graph->vertices_count(), my_graph);
  69.     round(&my_round, 0, from);
  70. }
  71.  
  72. int main() {
  73.     std::cout << "Hello, World !" << std::endl;
  74.     return 0;
  75. }
  76.  
  77. CListGraph::CListGraph(size_t num) {
  78.     vertices_list.resize(num);
  79. }
  80.  
  81. void CListGraph::add_vertexes(int necessary_num) {
  82.     while (vertices_list.size() < necessary_num + 1) {
  83.         v_road new_vertex;
  84.         vertices_list.push_back(new_vertex);
  85.     }
  86. }
  87.  
  88. void CListGraph::add_edge(int from, int to, int weight) {
  89.     int necessary_num = std::max(from, to);
  90.     if (vertices_list.size() < necessary_num + 1) {
  91.         add_vertexes(necessary_num);
  92.     }
  93.     Road new_road(to, weight);
  94.     Road new_reverse_road(from, weight);
  95.     vertices_list[from].push_back(new_road);
  96.     vertices_list[to].push_back(new_reverse_road);
  97. }
  98.  
  99. size_t CListGraph::vertices_count() const {
  100.     return vertices_list.size();
  101. }
  102.  
  103. void CListGraph::get_next_vertices(int vertex, v_road &vertices) const {
  104.     for (Road road_it : vertices_list[vertex]) {
  105.         vertices.push_back(road_it);
  106.     }
  107. }
  108.  
  109. void For_A_Round::get_next_vertices(int vertex, v_road &vertices) const {
  110.     v_road next_vertices;
  111.     my_graph->get_next_vertices(vertex, next_vertices);
  112.     for (Road road_it : next_vertices) {
  113.         if (! vertices_color[road_it.to]) {
  114.             vertices.push_back(road_it);
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement