Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ppltasks.h>
- #include <vector>
- using namespace std;
- void task(const vector<vector<size_t>>& roadConnections)
- {
- // We need to be sure that road matrix is equal by it's row sizes
- const size_t roadAmount = roadConnections.size();
- size_t* bestSummary = nullptr;
- size_t bestIndex = 0;
- for (size_t i = 0; i < roadAmount; i++)
- {
- size_t tempSummary = 0;
- for (size_t j = 0; j < roadAmount; j++)
- {
- if (j != i)
- {
- tempSummary += roadConnections[i][j];
- }
- }
- if (bestSummary == nullptr || tempSummary < *bestSummary)
- {
- bestSummary = new size_t(tempSummary);
- bestIndex = i;
- }
- }
- if (bestSummary == nullptr)
- {
- cout << "Something wrong" << endl;
- return;
- }
- cout << "The shortest vertex has index (0...N-1) = " << bestIndex << " with minimal road length to other vertexes ("
- << *
- bestSummary << ")";
- }
- int main()
- {
- const vector<vector<size_t>> roadConnections = {
- {0, 8, 3, 4},
- {8, 0, 3, 1},
- {3, 3, 0, 5},
- {4, 1, 5, 0}
- };
- task(roadConnections);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement