3
void dfs(int i, int n, vector<bool> &visited, vector<int> &cur, map<int, int> &ind, int &cnt,4
map<int, vector<int>> &mp) {9
for (int j = 0; j < mp[i].size(); j++) {10
dfs(mp[i][j], n, visited, cur, ind, cnt, mp);14
int minMalwareSpread(vector<vector<int>> &graph, vector<int> &initial) {16
map<int, vector<int>> mp; // Adjacency list creation for the graph17
for (int i = 0; i < n; i++) {18
for (int j = 0; j < n; j++) {19
if (i != j && graph[i][j] == 1) mp[i].push_back(j);22
map<int, int> ind; // This map is for storing the component number to which23
// a particular node belongs to24
vector<vector<int>> v; // Store all the connected components25
vector<bool> visited(n, false); // Visited array to keep track of the visited nodes26
int cnt = 0; // Current component number27
for (int i = 0; i < n; i++) {30
dfs(i, n, visited, cur, ind, cnt,31
mp); // Dfs call for getting single components36
map<int, vector<int>> help; // This map tells that how many node that is present in inital37
// vector are of same component38
for (int i = 0; i < initial.size(); i++) {39
int index = ind[initial[i]];40
help[index].push_back(initial[i]);43
int ans = n; // This loop is based on the logic described above44
for (auto it = help.begin(); it != help.end(); it++) {45
if (help[it->first].size() == 1) {46
int cover = v[it->first].size();49
ans = help[it->first][0];50
} else if (cover == sz) {51
if (help[it->first][0] < ans) ans = help[it->first][0];55
if (ans != n) return ans;56
for (int i = 0; i < initial.size(); i++) ans = min(ans, initial[i]);