fork download
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. const int MAX = 1e6+7;
  4. using namespace std;
  5.  
  6. vector<int> adj[MAX];
  7. int vis[MAX];
  8. int parent[MAX];
  9.  
  10. int find(int x){
  11. if(parent[x] != x) parent[x] = find(parent[x]);
  12. return parent[x];
  13. }
  14.  
  15. void merge(int a, int b){
  16. parent[b] = a;
  17. }
  18.  
  19. void solve(void){
  20. int n, m;
  21. cin >> n >> m;
  22. for(int i= 1; i<= m; i++){
  23. parent[i] = i;
  24. }
  25.  
  26. bool pretest_four = false;
  27. for(int i = 1 ; i <= n; i++){
  28. int k;
  29. cin >> k;
  30. if(k) pretest_four = true;
  31. int prev = -1;
  32. for(int i = 0; i < k; i++){
  33. int language;
  34. cin >> language;
  35. if(prev != -1){
  36. if(find(prev) == find(language)){
  37. continue;
  38. }
  39. else{
  40. merge(prev, language);
  41. }
  42. }
  43. prev = language;
  44. }
  45. }
  46.  
  47. int cc = 0;
  48. for(int i = 1; i <= n; i++){
  49. if(parent[i] == i){
  50. cc++;
  51. }
  52. }
  53.  
  54. if(!pretest_four){
  55. cout << n ;
  56. return;
  57. }
  58.  
  59. cout << cc-1;
  60.  
  61. }
  62. signed main() {
  63. fio;
  64. int t = 1;
  65. // cin>>t;
  66. while(t--)
  67. solve();
  68.  
  69. return 0;
  70. }
  71.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
Main.java:2: error: illegal character: '#'
#define pb push_back
^
Main.java:4: error: class, interface, or enum expected
using namespace std;
^
Main.java:6: error: class, interface, or enum expected
vector<int> adj[MAX];
^
Main.java:7: error: class, interface, or enum expected
int vis[MAX];
^
Main.java:8: error: class, interface, or enum expected
int parent[MAX];
^
Main.java:10: error: class, interface, or enum expected
int find(int x){
^
Main.java:12: error: class, interface, or enum expected
    return parent[x];
    ^
Main.java:13: error: class, interface, or enum expected
}
^
Main.java:17: error: class, interface, or enum expected
}
^
Main.java:21: error: class, interface, or enum expected
    cin >> n >> m;
    ^
Main.java:22: error: class, interface, or enum expected
    for(int i= 1; i<= m; i++){
    ^
Main.java:22: error: class, interface, or enum expected
    for(int i= 1; i<= m; i++){
                  ^
Main.java:22: error: class, interface, or enum expected
    for(int i= 1; i<= m; i++){
                         ^
Main.java:24: error: class, interface, or enum expected
    }
    ^
Main.java:27: error: class, interface, or enum expected
    for(int i = 1 ; i <= n; i++){
    ^
Main.java:27: error: class, interface, or enum expected
    for(int i = 1 ; i <= n; i++){
                    ^
Main.java:27: error: class, interface, or enum expected
    for(int i = 1 ; i <= n; i++){
                            ^
Main.java:29: error: class, interface, or enum expected
        cin >> k;
        ^
Main.java:30: error: class, interface, or enum expected
        if(k) pretest_four = true;
        ^
Main.java:31: error: class, interface, or enum expected
        int prev = -1;
        ^
Main.java:32: error: class, interface, or enum expected
        for(int i = 0; i < k; i++){
        ^
Main.java:32: error: class, interface, or enum expected
        for(int i = 0; i < k; i++){
                       ^
Main.java:32: error: class, interface, or enum expected
        for(int i = 0; i < k; i++){
                              ^
Main.java:34: error: class, interface, or enum expected
            cin >> language;
            ^
Main.java:35: error: class, interface, or enum expected
            if(prev != -1){
            ^
Main.java:38: error: class, interface, or enum expected
                }
                ^
Main.java:41: error: class, interface, or enum expected
                }
                ^
Main.java:44: error: class, interface, or enum expected
        }
        ^
Main.java:48: error: class, interface, or enum expected
    for(int i = 1; i <= n; i++){
    ^
Main.java:48: error: class, interface, or enum expected
    for(int i = 1; i <= n; i++){
                   ^
Main.java:48: error: class, interface, or enum expected
    for(int i = 1; i <= n; i++){
                           ^
Main.java:51: error: class, interface, or enum expected
        }
        ^
Main.java:56: error: class, interface, or enum expected
        return;
        ^
Main.java:57: error: class, interface, or enum expected
    }
    ^
Main.java:61: error: class, interface, or enum expected
}
^
Main.java:64: error: class, interface, or enum expected
int t = 1;
^
Main.java:66: error: class, interface, or enum expected
    while(t--)
    ^
Main.java:69: error: class, interface, or enum expected
    return 0;
    ^
Main.java:70: error: class, interface, or enum expected
}
^
41 errors
stdout
Standard output is empty