fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. string ltrim(const string &);
  6. string rtrim(const string &);
  7.  
  8.  
  9. /*
  10.  * Complete the 'countGroups' function below.
  11.  *
  12.  * The function is expected to return an INTEGER.
  13.  * The function accepts STRING_ARRAY related as parameter.
  14.  */
  15.  
  16. vector<int> g[200020];
  17. int vis[200020];
  18.  
  19. void dfs(int x) {
  20. vis[x] = 1;
  21. for (auto y: g[x]) if (vis[y] == 0) dfs(y);
  22. }
  23.  
  24. int countGroups(vector<string> related) {
  25. for (int i = 0; i <= related.size(); i++)
  26. g[i].clear(), vis[i] = 0;
  27.  
  28. for (int i = 0; i < related.size(); i++)
  29. for (int j = 0; j < related.size(); j++)
  30. if (related[i][j] == '1') g[i].push_back(j);
  31.  
  32. int ans = 0;
  33. for (int i = 0; i < related.size(); i++)
  34. if (vis[i] == 0) {
  35. dfs(i);
  36. ans++;
  37. }
  38.  
  39. return ans;
  40. }
  41. int main()
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:41:10: error: expected initializer at end of input
 int main()
          ^
stdout
Standard output is empty