## Input

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

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

N
Y
Y
N

## Code

 1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<vector>
5 #include<algorithm>
6 #define N (100009)
7 using namespace std;
8
9 struct Edge{int to,next;}edge[N<<2];
10 int n,q,a[N],f[N][18],Depth[N];
12 vector<int>v;
13
15 {
16     int x=0,w=1; char c=getchar();
17     while (c<'0' || c>'9') {if (c=='-') w=-1; c=getchar();}
18     while (c>='0' && c<='9') x=x*10+c-'0', c=getchar();
19     return x*w;
20 }
21
23 {
24     edge[++num_edge].to=v;
27 }
28
29 void DFS(int x,int fa)
30 {
31     f[x][0]=fa; Depth[x]=Depth[fa]+1;
32     for (int i=1; i<=17; ++i)
33         f[x][i]=f[f[x][i-1]][i-1];
34     for (int i=head[x]; i; i=edge[i].next)
35         if (edge[i].to!=fa) DFS(edge[i].to,x);
36 }
37
38 int LCA(int x,int y)
39 {
40     if (Depth[x]<Depth[y]) swap(x,y);
41     for (int i=17; i>=0; --i)
42         if (Depth[f[x][i]]>=Depth[y]) x=f[x][i];
43     if (x==y) return x;
44     for (int i=17; i>=0; --i)
45         if (f[x][i]!=f[y][i]) x=f[x][i], y=f[y][i];
46     return f[x][0];
47 }
48
49 void Solve(int x,int y,int lca)
50 {
51     v.clear();
52     while (x!=lca) v.push_back(a[x]), x=f[x][0];
53     while (y!=lca) v.push_back(a[y]), y=f[y][0];
54     v.push_back(a[lca]);
55     sort(v.begin(),v.end());
56     for (int i=1,s=v.size(); i<s-1; ++i)
57         if (1ll*v[i-1]+v[i]>v[i+1]) {puts("Y"); return;}
58     puts("N");
59 }
60
61 int main()
62 {
64     for (int i=1; i<=n; ++i) a[i]=read();
65     for (int i=1;  i<=n-1; ++i)
66     {
69     }
70     DFS(1,0);
71     while (q--)
72     {
82 }