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
// Complete the roadsAndLibraries function below. long roadsAndLibraries(int n, int c_lib, int c_road, vector
}
int main() { ofstream fout(getenv("OUTPUT_PATH"));
int q; cin >> q; cin.ignore(numeric_limits
for (int q_itr = 0; q_itr < q; q_itr++) { string nmC_libC_road_temp; getline(cin, nmC_libC_road_temp);
vector
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
for (int j = 0; j < 2; j++) { cin >> cities[i][j]; }
cin.ignore(numeric_limits
long result = roadsAndLibraries(n, c_lib, c_road, cities);
fout << result << " "; }
fout.close();
return 0; }
vector
input_string.erase(new_end, input_string.end());
while (input_string[input_string.length() - 1] == ' ') { input_string.pop_back(); }
vector
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
Get step-by-step solutions from verified subject matter experts
