Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bitset<102> a[152];
- int n, k;
- int t[152]; /// t[i] = j : i este in grupa cu j
- /// verific daca fata x si fata y au flori comune
- int FloriComune(int x, int y)
- {
- if ((a[x] & a[y]).count() > 0) return 1;
- return 0;
- }
- int main()
- {
- int i, j, x;
- ifstream fin("flori.in");
- ofstream fout("flori.out");
- fin >> n >> k;
- for (i = 1; i <= n; i++)
- for (j = 1; j <= k; j++)
- {
- fin >> x;
- a[i][x] = 1;
- }
- for (i = 1; i <= n; i++)
- {
- if (t[i] == 0) t[i] = i;
- for (j = i + 1; j <= n; j++)
- if (FloriComune(i, j)) t[j] = t[i];
- }
- for (i = 1; i <= n; i++)
- fout << t[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement