https://www.luogu.org/problem/P1197
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN=400005;
int n,m,k,fa[MAXN],p,cnt,lk;
bool b[MAXN],ins[MAXN];
stack <int > s;
stack <int > ans;
struct cyq{
int u,v;
}a[MAXN];
int get(){
char cc=getchar();
int res=