Can someone please help me out with this
I have made a dfs traversal with every node in query in a limited strength(depth) of the graph (birectional)
#include <bits/stdc++.h>
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using namespace std;
unsigned long long int MOD = 1e9 + 7;
unsigned long long int MAX = 1e6;
#define pi pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define pushb push_back
#define popf pop_front
#define popb pop_back
#define pushf push_front
#define first F
#define second S
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
typedef unsigned long long ull;
void printVis(vi vis)
{
cout << "VIS ARRAY :";
for (auto ele : vis)
{
cout << ele << " ";
}
cout << endl;
}
void printAdj(vi adj[], int nodes)
{
int i;
REP(i, 0, nodes)
{
cout << "\nnode :" << i << " : ";
for (auto ele : adj[i])
{
cout << ele << " ";
}
cout << endl;
}
}
void dfs(vi adj[], int present, vi &vis, int strength, vi &count)
{
vis[present] = 1;
//printVis(vis);
count[present]++;
if (strength > 0)
{
for (auto ele : adj[present])
{
if (!vis[ele])
{
dfs(adj, ele, vis, strength - 1, count);
}
}
}
}
int main()
{
fastIO
int t;
cin >> t;
while (t--)
{
int V,
E, Q;
cin >> V >> E >> Q;
int i;
vi adj[V];
REP(i, 0, E)
{
int s, d;
cin >> s >> d;
adj[s - 1].push_back(d - 1);
adj[d - 1].push_back(s - 1);
}
//printAdj(adj, V);
vi count(V, 0);
while (Q--)
{
int node, strength;
cin >> node >> strength;
vi vis(V, 0);
dfs(adj, node - 1, vis, strength, count);
}
int flag = 0;
//printVis(count);
string ans = "Yes";
for (auto ele : count)
{
if (ele == 0 || ele > 1)
{
flag = 1;
break;
}
}
if (flag)
ans = "No";
cout << ans << endl;
}
return 0;
}