in my .cpp file, I was able to change the list to a matrix and implement Floyd algorithm but I did it this way, I declared the matrices inside the function
If your data is complicated to create -- a class for instance -- instead of creating a temporary to push back you can create in-place an element with emplace_back (requires C++11 or later): https://en.cppreference.com/w/cpp/container/vector/emplace_back
Resizing a std::vector "on the fly," adding new elements, repeatedly can be an expensive operation. It is better to specify the size when you create your std::vector if possible.
Adding elements to a sized std::vector is a simple operation of modifying the elements using operator[] or the .at operator.