Advertisement
CyberN00b

Untitled

Jan 8th, 2023
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. struct matrix{
  2.  
  3.     matrix(int count_of_vertex) : m(vector<vector<int> >(count_of_vertex, vector<int>(0))), edge_count(0) {}
  4.  
  5.     void add_edge(int first_vertex, int second_vertex, int weight) {
  6.         for (auto& x : m)
  7.             x.push_back(0);
  8.         ++edge_count;
  9.         m[first_vertex].back() = weight;
  10.         m[second_vertex].back() = weight;
  11.     }
  12.  
  13.     int get_weight(int first_vertex, int second_vertex) {
  14.         int weight = 0;
  15.         for (long long i = 0; i < m[first_vertex].size(); ++i)
  16.             if (m[first_vertex][i] > 0 && m[second_vertex][i] > 0)
  17.                 weight += m[first_vertex][i];
  18.         return weight;
  19.     }
  20.    
  21.     void add_vertex(int count=1) {
  22.         for (int i = 0; i < count; ++i)
  23.             m.push_back(std::move(vector<int>(edge_count, 0)));
  24.     }
  25.    
  26.     vector<vector<int> > get_matrix() {
  27.         return m;
  28.     }
  29.    
  30. private:
  31.    
  32.     long long edge_count;
  33.     vector<vector<int>> m;
  34.  
  35. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement