How to set a graph in C++ (Mobius Prism)

Hello, how do I set such a graph in C++?

Then n is a natural number everywhere. Let's call a graph with sets of vertices

V = {0, 1, 2, . . ., 2n−1}

And edges

E = {(i, i + 1) | i = 0, 2n − 1, i четное} ∪ {(i, i + 2) | i = 0, 2n − 1} 

(addition modulo 2n) by the prism P (n).

I use the adjacency matrix for the representation.

Author: Andrej Levkovitch, 2017-12-14

1 answers

Well, you have some kind of adjacency matrix, like

vector<vector<int>> V(2*n, vector<int>(2*n,0));

Then-just in cycles:

{(i, i+1) | i = 0, 2n-1, i is even}

for(int i = 0; i < 2*n; ++i)
{ 
    if (i%2) continue;  // нечетное

    V[i%(2*n)][(i+1)%(2*n)] = 1;
    // Если не ориентированный -
    V[(i+1)%(2*n)][i%(2*n)] = 1;
}

{(i, i+2) | i = 0, 2n-1} - similar to

for(int i = 0; i < 2*n; ++i)
{ 
    V[i%(2*n)][(i+2)%(2*n)] = 1;
    // Если не ориентированный -
    V[(i+2)%(2*n)][i%(2*n)] = 1;
}

"In my opinion, so " (c) Pooh

 3
Author: Harry, 2017-12-14 11:11:02