Comments

if(k==1) ans can be YES if one of n,m is 1. Also tha ans is not always no for n==m.

I got a tle in D because of using long long instead of int.

This is giving a wrong answer can anybody help me why.

include <bits/stdc++.h>

define loop(i,n) for(int i=0;i<n;i++)

using namespace std; class graph{ int n; int m; vector<vector>g;

public: graph(int node,int edge){ g.resize(node); n=node; m=edge; } void addedge(int a,int b){ g[a].push_back(b); g[b].push_back(a); } void display(){ loop(i,n){ cout<<i<<"-->"; for(auto x:g[i]){ cout<<x<<" "; } } cout<<endl; } bool bfs(int src,int time,vector&vis){ queue q; q.push(src); time=time+1; if(vis[src]==1){ return 0; } while(!q.empty()&&time){ int sz=q.size(); time--; // cout<<tp<<" "; while(sz--){ int tp=q.front(); vis[tp]=1; q.pop(); for(auto x:g[tp]){ if(vis[x]==0){ q.push(x); } else if(time>0){ return 0; } } } } return 1; } bool check(vector<pair<int,int>>v){ vector vis(n,0); bool ans; for(auto x:v){ int src=x.first; int power=x.second; ans=bfs(src,power,vis); if(ans==0){ //cout<< return 0; } } loop(i,n){ if(vis[i]==0){ //cout<<"yes"<<i<<endl; return 0; } } return 1; } }; int main() { int t; cin>>t; while(t--){ int n,r,m; cin>>n>>r>>m; graph g(n,r); loop(i,r){ int a,b; cin>>a>>b; a--; b--; g.addedge(a,b); } // g.display();

vector<pair<int,int>>v;
loop(i,m){
int a,b;
cin>>a>>b;
a--;
v.push_back(make_pair(a,b));
}

// for(auto x:v){ // cout<<x.first<<" "<<x.second<<endl; // } bool ans=g.check(v); if(ans==0){ cout<<"No"<<endl; } else{ cout<<"Yes"<<endl; } } return 0; }