#include #define Maxn 200007 #define inf 200000007 using namespace std; int read() { int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,cnt; int last[Maxn],pre[Maxn*2],other[Maxn*2],val[Maxn*2]; int fa[Maxn],rk[Maxn]; int find(int x) { if (x==fa[x]) return fa[x]; fa[x]=find(fa[x]); return fa[x]; } void mdf(int x,int y) { x=find(x),y=find(y); if (x==y) return; if (rk[x]