#include #include #include using namespace std; using ll = long long; using ull = unsigned long long; using l3 = __int128; using pint = pair; using pll = pair; using tint = tuple; using tll = tuple; template using min_priority_queue = priority_queue, greater>; #define rep(i, n) for (int i = 0; i < (n); ++i) template bool chmax(T &a, const T &b){if(a bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;} const int inf = 1e9; const ll linf = 1e18; const int dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0}; int main(){ int n,m;cin>>n>>m; vector> graph(n); rep(i,m){ int u,v;cin>>u>>v; u--,v--; graph[u].push_back(v); graph[v].push_back(u); } int l;cin>>l; vector dp(n,-1); rep(i,l){ int j,k;cin>>j>>k; j--; chmax(dp[j],k); } rep(i,1000) rep(v,n) for(auto& nv:graph[v])chmax(dp[nv],dp[v]-1); queue q; vector dist(n,inf); q.push(0); dist[0]=0; while(q.size()){ int v=q.front();q.pop(); for(auto& nv:graph[v]){ if(dp[nv]>=0||dist[nv]<=dist[v]+1)continue; dist[nv]=dist[v]+1; q.emplace(nv); } } if(dist[n-1]==inf)cout<<"No\n"; else cout<<"Yes\n"<