Advertisement
Ankit_132

B

Sep 25th, 2023
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n;
  14.         cin>>n;
  15.        
  16.         vector<vector<int>> v(n);
  17.        
  18.         vector<int> cnt(100);
  19.        
  20.         for(int i=0; i<n; i++)
  21.         {
  22.             int k;
  23.             cin>>k;
  24.            
  25.             v[i].resize(k);
  26.             for(auto &e: v[i])      cin>>e;
  27.            
  28.             for(auto e: v[i])      cnt[e]++;
  29.         }
  30.        
  31.         int ans = 0;
  32.         vector<int> cnt2(100);
  33.        
  34.         for(int i=0; i<100; i++)
  35.         {
  36.             if(!cnt[i])     continue;
  37.            
  38.             fill(cnt2.begin(), cnt2.end(), 0);
  39.            
  40.             for(int j=0; j<n; j++)
  41.             {
  42.                 if(binary_search(v[j].begin(), v[j].end(), i))       continue;
  43.                
  44.                 for(auto e: v[j])       cnt2[e] = 1;
  45.             }
  46.            
  47.             ans = max(ans, accumulate(cnt2.begin(), cnt2.end(), 0));
  48.         }
  49.        
  50.         cout<<ans<<"\n";
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement