思路:
考虑时光倒流 这不就是并查集裸题了…………….//By SiriusRen#include#include #include using namespace std;#define N 500500int n,q,xx,yy,v[N],first[N],next[N],tot,fa[N],f[N],ask[N],vis[N],ans[N];char op[N][5];int find(int x){return x==f[x]?x:f[x]=find(f[x]);}void add(int x,int y){v[tot]=y,next[tot]=first[x],first[x]=tot++;}void dfs(int x){for(int i=first[x];~i;i=next[i])if(v[i]!=fa[x])fa[v[i]]=x,dfs(v[i]);}int main(){ freopen("tree.in","r",stdin); freopen("tree.out","w",stdout); memset(first,-1,sizeof(first)); scanf("%d%d",&n,&q); for(int i=1;i