In my C++ project, I have three classes, `Particle`, `Contact`, and `Network`. The `Network` class will have N particles (`std::vector<Particle> particles`) and Nc contacts (`std::vector<Contact> contacts`). `Particle` objects will each have a number of contacts, represented by `Contact` objects, and contacts are shared by pairs of particles.

It will be necessary for me to know what contacts a specific particle has, and I have decided to be able to obtain that information through the `Network` object (e.g., using `network.getContacts(Particle particle)`).

My question can be broken into two parts:

**First**, what would be an efficient and community-recommended way to store the contacts for each particle?

I believe that I can either create a vector of vector of shared pointers to `Contact` objects, `vector<vector<shared_ptr<Contact>>> prtContacts` (where I have left off `std::` for ease of viewing), so that `prtContacts[i]` will contain a vector of shared pointers to the contacts of the `i`th particle. It has been suggested that using `shared_ptr` in this context is useful, as it will ensure that I am not creating duplicate `Contact` objects for two particles with a shared contact. Is there an alternative method that would make more sense?

**Second**, if I do end up creating `prtContacts` as defined above, what is the best way to initialize it? My current thinking is to have an initial loop that initializes `std::vector<Contact> contacts` with the Nc contacts and then have a second loop that initializes `prtContacts` with shared pointers to the Contacts. Is that reasonable or, again, are there alternative, more efficient, approaches?

Thank you!

---

**Some additional information:**

The number of particles, N, will range from `O(10^1)` to perhaps `O(10^4)`. The number of contacts per particle will most likely not exceed 6-7, but will be allowed to vary. Each contact will have a position and contact force (2-component vector) associated with it, and both positions and contact forces will be allowed to vary during the course of simulations (e.g., Monte Carlo simulations).