#include #include #include #include #include #define MAX 10001 using namespace std; typedef long long int lli; int f[MAX]; int k[MAX]; int find(int x){ if(f[x]==x)return x; else return f[x]=find(f[x]); } int u(int a,int b){ int fa=find(a); int fb=find(b); if(fa==fb)return 0; // cout<<"u:"<>n>>m; for(int i=0;i>a>>b; a--;b--; if(k[a]==k[b]){ if(find(a)>find(b)) u(a,b); else if(find(a)