Mephistopheles_

Система пересекающихся множеств

Jan 19th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<string>
  5. #include<set>
  6. #include<functional>
  7. using ll= unsigned long long;
  8. using namespace std;
  9. int main() {
  10.     ios::sync_with_stdio(0);
  11.     cin.tie(0);
  12.     int n, m, k, a, b;
  13.     string s;
  14.     vector<set<int>>e(100);
  15.     cin >> m >> n;
  16.     cin >> k;
  17.     vector<set<int>>v;
  18.     vector<vector<int>>vy;
  19.     v.resize(n);  
  20.     vy.reserve(1000);
  21.     for (int i = 0; i < k; ++i) {
  22.         cin >> s;
  23.         if (s == "ADD") {
  24.             cin >> a >> b;
  25.             e[a - 1].insert(b);
  26.             v[b - 1].insert(a);
  27.  
  28.         }
  29.         if (s == "LISTSETSOF") {
  30.             vy.push_back({});
  31.             cin >> a;
  32.             if (e[a-1].size() == 0)vy[vy.size() - 1].push_back(-1);
  33.             else for (int j : e[a-1])vy[vy.size() - 1].push_back(j);
  34.         }
  35.         if (s == "LISTSET") {
  36.             vy.push_back({});
  37.             cin >> a;
  38.             if (v[a - 1].size() == 0)vy[vy.size() - 1].push_back(-1);
  39.             else for (int j : v[a-1])vy[vy.size() - 1].push_back(j);
  40.         }
  41.     }
  42.     for (auto r : vy) {
  43.         for (int y : r)cout << y << ' ';
  44.         cout << '\n';
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment