using namespace std;
vector<long long int>edges[100];
vector<long long int>result;
long long int visited[1000],c=0;
long long int dfs(long long int s)
{
long long int x,y,z;
if(visited[s]==0)
{
visited[s]=1;
for(x=0;x<edges[s].size();x++)
{
z=edges[s][x];
if(visited[z]==0)
{
result.push_back(z);
dfs(z);
}
}
}
}
int main()
{
long long int i,j,k,l,u,v,n,e,t,ct;
cin>>t;
for(j=1;j<=t;j++)
{
ct=0;
cin>>n>>e;
for(i=1;i<=e;i++)
{
cin>>u>>v;
if(i==1)
{
l=u;
}
edges[u].push_back(v);
edges[v].push_back(u);
}
result.push_back(l);
for(i=1;i<=n;i++)
{
if(visited[i]==0)
{
if(i==1)
{
dfs(l);
}
else
{
ct=1;
break;
}
}
}
if(ct==0)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
memset(visited,0, sizeof visited);
memset(edges,0,sizeof edges);
}
return 0;
}
0 comments:
Post a Comment