daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bitset<102> a[152];
  6. int n, k;
  7. int t[152]; /// t[i] = j : i este in grupa cu j
  8. /// verific daca fata x si fata y au flori comune
  9. int FloriComune(int x, int y)
  10. {
  11.     if ((a[x] & a[y]).count() > 0) return 1;
  12.     return 0;
  13. }
  14.  
  15. int main()
  16. {
  17.     int i, j, x;
  18.     ifstream fin("flori.in");
  19.     ofstream fout("flori.out");
  20.     fin >> n >> k;
  21.     for (i = 1; i <= n; i++)
  22.         for (j = 1; j <= k; j++)
  23.         {
  24.             fin >> x;
  25.             a[i][x] = 1;
  26.         }
  27.     for (i = 1; i <= n; i++)
  28.         {
  29.             if (t[i] == 0) t[i] = i;
  30.             for (j = i + 1; j <= n; j++)
  31.                 if (FloriComune(i, j)) t[j] = t[i];
  32.         }
  33.     for (i = 1; i <= n; i++)
  34.         fout << t[i] << " ";
  35.     return 0;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top