Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct matrix{
- matrix(int count_of_vertex) : m(vector<vector<int> >(count_of_vertex, vector<int>(0))), edge_count(0) {}
- void add_edge(int first_vertex, int second_vertex, int weight) {
- for (auto& x : m)
- x.push_back(0);
- ++edge_count;
- m[first_vertex].back() = weight;
- m[second_vertex].back() = weight;
- }
- int get_weight(int first_vertex, int second_vertex) {
- int weight = 0;
- for (long long i = 0; i < m[first_vertex].size(); ++i)
- if (m[first_vertex][i] > 0 && m[second_vertex][i] > 0)
- weight += m[first_vertex][i];
- return weight;
- }
- void add_vertex(int count=1) {
- for (int i = 0; i < count; ++i)
- m.push_back(std::move(vector<int>(edge_count, 0)));
- }
- vector<vector<int> > get_matrix() {
- return m;
- }
- private:
- long long edge_count;
- vector<vector<int>> m;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement