fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. inline set<int> intersect(set<int> a, set<int> b) {
  9. set<int> result;
  10. set_intersection(
  11. a.begin(), a.end(),
  12. b.begin(), b.end(),
  13. inserter(result, result.begin())
  14. );
  15. return result;
  16. }
  17.  
  18. int main() {
  19. int n; cin >> n;
  20.  
  21. vector<set<int>> s(n);
  22. int k, x;
  23.  
  24. for (int i = 0; i < n; i++) {
  25. cin >> k;
  26. for (int j = 0; j < k; j++) {
  27. cin >> x;
  28. s[i].insert(x);
  29. }
  30. }
  31.  
  32. set<int> c = intersect(s[0], s[1]);
  33. for (int i = 0; i < n-1; i++) {
  34. for (int j = i+1; j < n; j++) {
  35. if (intersect(s[i], s[j]) != c) {
  36. cout << "NO\n";
  37. return 0;
  38. }
  39. }
  40. }
  41.  
  42. cout << "YES\n";
  43. cout << c.size() << "\n";
  44. cout << s[0].size() - c.size();
  45. for (int i = 1; i < n; i++) cout << " " << s[i].size() - c.size();
  46. cout << "\n";
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5292KB
stdin
3
2 1 2
2 2 3
2 1 3
stdout
NO