Advertisement
Korotkodul

gaz_N5

Jan 13th, 2023 (edited)
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. int n, k;
  51. vector <vector <int> > G;
  52.  
  53.  
  54. bool in_it(vector <int> a, vector <int> b) {//a inside b
  55.     if (a.size() > b.size()) {
  56.         return 0;
  57.     }
  58.     for (int i = 0; i < a.size(); ++i) {
  59.         if (a[i] != b[i]) {
  60.             return 0;
  61.         }
  62.     }
  63.     return 1;
  64. }
  65.  
  66. vector <bool> in, out;
  67.  
  68. void dfs(int v) {
  69.     in[v] = 1;
  70.     for (int u: G[v]) {
  71.         if (in[u]) {
  72.             continue;
  73.         }
  74.         out[v] = 1;
  75.         dfs(u);
  76.     }
  77. }
  78.  
  79. int main() {
  80.     ios::sync_with_stdio(0);
  81.     cin.tie(0);
  82.     cout.tie(0);
  83.     cin >> n >> k;
  84.     G.resize(n);
  85.     vector <vector <int> > ing(n);
  86.     for (int i = 0; i < n; ++i) {
  87.         int m; cin >> m;
  88.         for (int j = 0; j < m; ++j) {
  89.             int x; cin >> x;
  90.             ing[i].pb(x);
  91.         }
  92.         sort(ing[i].begin(), ing[i].end());
  93.     }
  94.     for (int i = 0; i < n; ++i) {
  95.         for (int j = 0; j < n && j != n; ++j) {
  96.             if (in_it(ing[i], ing[j])) {
  97.                 G[i].pb(j);
  98.             }
  99.             if (in_it(ing[j], ing[i])) {
  100.                 G[j].pb(i);
  101.             }
  102.         }
  103.     }
  104.     in.resize(n, 0);
  105.     out.resize(n, 0);
  106.     for (int i = 0; i < n; ++i) {
  107.         if (in[i]) {
  108.             continue;
  109.         }
  110.         dfs(i);
  111.     }
  112.     int ans = 0;
  113.     for (int i = 0; i < n; ++i) {
  114.         if (!out[i]) {
  115.             ans++;
  116.         }
  117.     }
  118.     cout << ans;
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement