#include <bits/stdc++.h>
using namespace std;
//variable
#define ld long double
#define ll long long
#define db double
#define ii pair<int,int>
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
//vector
#define pb push_back
#define all(v) v.begin(),v.end()
#define len(a) (int)a.length()
#define sz(a) (int)a.size()
//mask
#define BIT(i) (1LL<<(i))
//better code, debugger
#define watch(n) cerr << #n << ": " << n << endl
#define debug(x) for (auto p: x) cerr<<p<<' ';cerr<<endl
#define forw(i,j,z) for(int i=(int)j;i<=(int)z;i++)
#define ford(i,j,z) for (int i=(int)j;i>=(int)z;i--)
#define fIlE "closing."
//auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
//mt19937 RAND(seed);
const int mod = 998244353;
inline int add(int u,int v){u+=v;if(u>=mod)u-=mod;return u;}
inline int dec(int u,int v){u-=v;if(u<0)u+=mod;return u;}
inline int mul(int u,int v){return (ll)u*v%mod;}
int n, m;
const int N = 3000 + 2;
ii edge[N];
vector<int> a[N], ok[N];
int per[N];
bool del[N];
struct DSU{
int root = 0;
};
DSU dsu[N];
int findset(int u)
{
return dsu[u].root == u ? u : dsu[u].root = findset(dsu[u].root);
}
void solve()
{
cin >> n >> m;
forw(i, 1, m){
int u, v;
cin >> u >> v;
edge[i] = mp(u, v);
a[u].pb(i);
a[v].pb(i);
}
forw(i, 1, n){
cin >> per[i];
for (int e : a[per[i]])
{
if (!del[e])
{
del[e] = 1;
ok[i].pb(e);
}
}
}
vector<string> ans;
int cnt = 0;
ford(i, n, 1){
dsu[per[i]].root = per[i];
++cnt;
for (int e : ok[i])
{
int u = edge[e].f, v = edge[e].s;
u = findset(u), v = findset(v);
if (u == v) continue;
dsu[u].root = v;
cnt--;
}
ans.pb(cnt <= 1 ? "YES\n" : "NO\n");
}
ford(i, n - 1, 0) cout << ans[i];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen(fIlE"in", "r"))
freopen(fIlE"in","r",stdin), freopen(fIlE"out","w",stdout);
//time_t TIME_TU=clock();
int t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G1vZCA9IDk5ODI0NDM1MzsKaW5saW5lIGludCBhZGQoaW50IHUsaW50IHYpe3UrPXY7aWYodT49bW9kKXUtPW1vZDtyZXR1cm4gdTt9CmlubGluZSBpbnQgZGVjKGludCB1LGludCB2KXt1LT12O2lmKHU8MCl1Kz1tb2Q7cmV0dXJuIHU7fQppbmxpbmUgaW50IG11bChpbnQgdSxpbnQgdil7cmV0dXJuIChsbCl1KnYlbW9kO30KaW50IG4sIG07CmNvbnN0IGludCBOID0gMzAwMCArIDI7CmlpIGVkZ2VbTl07CnZlY3RvcjxpbnQ+IGFbTl0sIG9rW05dOwppbnQgcGVyW05dOwpib29sIGRlbFtOXTsKc3RydWN0IERTVXsKICAgIGludCByb290ID0gMDsKfTsKRFNVIGRzdVtOXTsKCmludCBmaW5kc2V0KGludCB1KQp7CiAgICByZXR1cm4gZHN1W3VdLnJvb3QgPT0gdSA/IHUgOiBkc3VbdV0ucm9vdCA9IGZpbmRzZXQoZHN1W3VdLnJvb3QpOwp9CnZvaWQgc29sdmUoKQp7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9ydyhpLCAxLCBtKXsKICAgICAgICBpbnQgdSwgdjsKICAgICAgICBjaW4gPj4gdSA+PiB2OwogICAgICAgIGVkZ2VbaV0gPSBtcCh1LCB2KTsKICAgICAgICBhW3VdLnBiKGkpOwogICAgICAgIGFbdl0ucGIoaSk7CiAgICB9CiAgICBmb3J3KGksIDEsIG4pewogICAgICAgIGNpbiA+PiBwZXJbaV07CiAgICAgICAgZm9yIChpbnQgZSA6IGFbcGVyW2ldXSkKICAgICAgICB7CiAgICAgICAgICAgIGlmICghZGVsW2VdKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBkZWxbZV0gPSAxOwogICAgICAgICAgICAgICAgb2tbaV0ucGIoZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICB2ZWN0b3I8c3RyaW5nPiBhbnM7CiAgICBpbnQgY250ID0gMDsKICAgIGZvcmQoaSwgbiwgMSl7CiAgICAgICAgZHN1W3BlcltpXV0ucm9vdCA9IHBlcltpXTsKICAgICAgICArK2NudDsKICAgICAgICBmb3IgKGludCBlIDogb2tbaV0pCiAgICAgICAgewogICAgICAgICAgICBpbnQgdSA9IGVkZ2VbZV0uZiwgdiA9IGVkZ2VbZV0uczsKICAgICAgICAgICAgdSA9IGZpbmRzZXQodSksIHYgPSBmaW5kc2V0KHYpOwogICAgICAgICAgICBpZiAodSA9PSB2KSBjb250aW51ZTsKICAgICAgICAgICAgZHN1W3VdLnJvb3QgPSB2OwogICAgICAgICAgICBjbnQtLTsKICAgICAgICB9CiAgICAgICAgYW5zLnBiKGNudCA8PSAxID8gIllFU1xuIiA6ICJOT1xuIik7CiAgICB9CiAgICBmb3JkKGksIG4gLSAxLCAwKSBjb3V0IDw8IGFuc1tpXTsKfQpzaWduZWQgbWFpbigpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKICAgIGlmIChmb3BlbihmSWxFImluIiwgInIiKSkKICAgICAgICBmcmVvcGVuKGZJbEUiaW4iLCJyIixzdGRpbiksIGZyZW9wZW4oZklsRSJvdXQiLCJ3IixzdGRvdXQpOwogICAgLy90aW1lX3QgVElNRV9UVT1jbG9jaygpOwogICAgaW50IHQ9MTsKLy8gICAgY2luPj50OwogICAgd2hpbGUodC0tKQogICAgICAgIHNvbHZlKCk7CiAgICAvL3RpbWVfdCBUSU1FX1RWPWNsb2NrKCk7CiAgICAvL2NlcnI8PChkYikoVElNRV9UVi1USU1FX1RVKS9DTE9DS1NfUEVSX1NFQzw8ZW5kbDsKICAgIHJldHVybiAwOwp9Cg==