daily pastebin goal
22%
SHARE
TWEET

Graph (undirected, weighted)

keverman Jan 11th, 2019 15 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct edge
  2. {
  3.     int weight, to;
  4.  
  5.     edge() {}
  6.     edge(int new_weight, int new_to)
  7.     {
  8.         weight = new_weight;
  9.         to = new_to;
  10.     }
  11. };
  12.  
  13. class graph
  14. {
  15.     private:
  16.  
  17.         std::vector<std::vector<edge>> edges;
  18.  
  19.     public:
  20.  
  21.         graph(int size)
  22.         {
  23.             edges.resize(size);
  24.         }
  25.  
  26.         void add(int from, int to, int weight)
  27.         {
  28.             edges[from].push_back(edge(weight, to));
  29.             edges[to].push_back(edge(weight, from));
  30.         }
  31.  
  32.         int size()
  33.         {
  34.             return edges.size();
  35.         }
  36. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top