Question: an you help me code? Output Format For each query, print an integer denoting the minimum cost of making libraries accessible to all the citizens

an you help me code?

Output Format

For each query, print an integer denoting the minimum cost of making libraries accessible to all the citizens on a new line.

Sample Input

2 3 3 2 1 1 2 3 1 2 3 6 6 2 5 1 3 3 4 2 4 1 2 2 3 5 6 Sample Output

4 12

#include

using namespace std;

vector split_string(string);

// Complete the roadsAndLibraries function below. long roadsAndLibraries(int n, int c_lib, int c_road, vector> cities) {

}

int main() { ofstream fout(getenv("OUTPUT_PATH"));

int q; cin >> q; cin.ignore(numeric_limits::max(), ' ');

for (int q_itr = 0; q_itr < q; q_itr++) { string nmC_libC_road_temp; getline(cin, nmC_libC_road_temp);

vector nmC_libC_road = split_string(nmC_libC_road_temp);

int n = stoi(nmC_libC_road[0]);

int m = stoi(nmC_libC_road[1]);

int c_lib = stoi(nmC_libC_road[2]);

int c_road = stoi(nmC_libC_road[3]);

vector> cities(m); for (int i = 0; i < m; i++) { cities[i].resize(2);

for (int j = 0; j < 2; j++) { cin >> cities[i][j]; }

cin.ignore(numeric_limits::max(), ' '); }

long result = roadsAndLibraries(n, c_lib, c_road, cities);

fout << result << " "; }

fout.close();

return 0; }

vector split_string(string input_string) { string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) { return x == y and x == ' '; });

input_string.erase(new_end, input_string.end());

while (input_string[input_string.length() - 1] == ' ') { input_string.pop_back(); }

vector splits; char delimiter = ' ';

size_t i = 0; size_t pos = input_string.find(delimiter);

while (pos != string::npos) { splits.push_back(input_string.substr(i, pos - i));

i = pos + 1; pos = input_string.find(delimiter, i); }

splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));

return splits; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!