Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- using namespace std;
- #define TASK "formation"
- struct sovietsky_soldat {
- int left, right;
- sovietsky_soldat() {
- left = right = 0;
- }
- };
- vector < sovietsky_soldat > p;
- void left(int a, int b) {
- if (p[b].left != 0) {
- p[a].left = p[b].left;
- }
- p[b].left = a;
- p[a].right = b;
- }
- void right(int a, int b) {
- if (p[b].right != 0) {
- p[a].right = p[b].right;
- }
- p[b].right = a;
- p[a].left = b;
- }
- void leave(int a) {
- if (p[a].left != 0) {
- p[p[a].right].left = p[a].left;
- }
- if (p[a].right != 0) {
- p[p[a].left].right = p[a].right;
- }
- p[a] = sovietsky_soldat();
- }
- void name(int a) {
- cout << p[a].left << " " << p[a].right << "\n";
- }
- int main() {
- #ifdef _DEBUG
- freopen("debug.in", "r", stdin);
- freopen("debug.out", "w", stdout);
- #else
- freopen(TASK".in", "r", stdin);
- freopen(TASK".out", "w", stdout);
- #endif // _DEBUG
- int n, m, a, b;
- string s;
- cin >> n >> m;
- for (int i = 0; i <= n; i++) {
- p.push_back(sovietsky_soldat());
- }
- for (int i = 0; i < m; i++) {
- cin >> s >> a;
- if (s == "left") {
- cin >> b;
- left(a, b);
- }
- if (s == "right") {
- cin >> b;
- right(a, b);
- }
- if (s == "leave") {
- leave(a);
- }
- if (s == "name") {
- name(a);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement