WA on #3 to #10.
#include <bits/stdc++.h>
using namespace std;
int q, op, x, y, cnt;
struct node {
int l, r;
} a[1000010];
void insert(int x, int y) {
a[y].l = x;
a[y].r = a[x].r;
a[x].r = y, a[a[y].r].l = y;
}
int nxet(int x) {
return a[x].r;
}
void pop(int x) {
a[a[x].l].r = a[x].r;
a[a[x].r].l = a[x].l;
a[x] = {0, 0};
}
signed main() {
cin >> q;
while (q--) {
cin >> op;
if (op == 1) cin >> x >> y, insert(x, y);
else if (op == 2) cin >> x, cout << nxet(x) << '\n';
else cin >> x, pop(x);
}
}