Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
- #pragma GCC optimize 03
- #pragma GCC optimize("unroll-loops")
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- #include <cmath>
- #include <ctime>
- #include <vector>
- #include <deque>
- #include <queue>
- #include <set>
- #include <map>
- #include <stack>
- #include <string>
- #include <random>
- #include <numeric>
- #include <unordered_set>
- typedef long long ll;
- typedef long double lb;
- #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define file_in freopen("input.txt", "r", stdin);
- #define file_in_out freopen("knapsack.in", "r", stdin); freopen("knapsack.out", "w", stdout);
- #define mp make_pair
- #define all(x) (x).begin(), (x).end()
- #define fi first
- #define se second
- using namespace std;
- template<typename T>
- istream& operator>>(istream &in, vector<T> &v) {
- for (auto &it : v) {
- in >> it;
- }
- return in;
- }
- template<typename T>
- ostream& operator<<(ostream &out, vector<T> &v) {
- if (!v.empty()) {
- out << v.front();
- for (int i = 1; i < v.size(); ++i) {
- out << " " << v[i];
- }
- }
- return out;
- }
- struct unions {
- int m;
- vector<map<int, int>> a;
- unions(int _m) {
- m = _m;
- a.resize(m + 1);
- }
- void ADD(int s, int e) {
- a[s][e] = 1;
- }
- void DELETE(int s, int e) {
- a[s][e] = 0;
- }
- void CLEAR(int s) {
- a[s].clear();
- }
- void LIST_SET(int s) {
- vector<int> ans;
- for (auto element : a[s]) {
- if (element.se) {
- ans.push_back(element.fi);
- }
- }
- if (ans.empty()) {
- cout << -1;
- } else {
- cout << ans;
- }
- cout << endl;
- }
- void privet(int e) {
- vector<int> ans;
- for (int i = 0; i < m + 1; ++i) {
- if (a[i][e] != 0) {
- ans.push_back(i);
- }
- }
- if (ans.empty()) {
- cout << -1;
- } else {
- cout << ans;
- }
- cout << endl;
- }
- };
- int main() {
- fast
- // file_in
- // file_in_out
- ll n;
- int m, k;
- cin >> n >> m >> k;
- unions u(m);
- string type;
- int e, s;
- while (k--) {
- cin >> type;
- if (type == "ADD") {
- cin >> e >> s;
- u.ADD(s, e);
- }
- if (type == "DELETE") {
- cin >> e >> s;
- u.DELETE(s, e);
- }
- if (type == "CLEAR") {
- cin >> s;
- u.CLEAR(s);
- }
- if (type == "LISTSET") {
- cin >> s;
- u.LIST_SET(s);
- }
- if (type == "LISTSETOF") {
- cin >> e;
- u.privet(e);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement