# [BZOJ3251]树上三角形

Description

Input

n,q<=100000，点权范围[1,2^31-1]

Output

Sample Input
5 5
1 2 3 4 5
1 2
2 3
3 4
1 5
0 1 3
0 4 5
1 1 4
0 2 5
0 2 3

Sample Output
N
Y
Y
N

1,2,3,5,8,11,...

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
}
inline int frd(){
int x=0,f=1;char ch=gc();
for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')    f=-1;
for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0)    putchar('-'),x=-x;
if (x>9)	print(x/10);
putchar(x%10+'0');
}
const int N=1e5;
vector<ui>vec;
int v[N+10];
struct S1{
int pre[(N<<1)+10],now[N+10],child[(N<<1)+10],tot;
int deep[N+10],fa[N+10],Rem[N+10],top[N+10],size[N+10];
void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
void insert(int x,int y){join(x,y),join(y,x);}
void dfs(int x){
deep[x]=deep[fa[x]]+1,size[x]=1;
for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
if (son==fa[x])	continue;
fa[son]=x,dfs(son);
size[x]+=size[son];
if (size[Rem[x]]<size[son])	Rem[x]=son;
}
}
void build(int x){
if (!x)	return;
top[x]=Rem[fa[x]]==x?top[fa[x]]:x;
build(Rem[x]);
for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
if (son==fa[x]||son==Rem[x])	continue;
build(son);
}
}
int Lca(int x,int y){
while (top[x]!=top[y]){
if (deep[top[x]]<deep[top[y]])	swap(x,y);
x=fa[top[x]];
}
return deep[x]<deep[y]?x:y;
}
bool work(int x,int y){
int lca=Lca(x,y);
if (deep[x]+deep[y]-2*deep[lca]+1>50)	return 1;
vec.clear(); vec.push_back(v[lca]);
for (;x!=lca;x=fa[x])	vec.push_back(v[x]);
for (;y!=lca;y=fa[y])	vec.push_back(v[y]);
sort(vec.begin(),vec.end());
for (vector<ui>::iterator i=vec.begin();i!=vec.end();i++)
for (vector<ui>::iterator j=i+1;j!=vec.end();j++)
for (vector<ui>::iterator k=j+1;k!=vec.end();k++)
if (*k<*j+*i)	return 1;
return 0;
}
}HLD;//Heavy Light Decomposition
int main(){