pat-1122

It seems to have done something similar before 

#include<iostream>
#include<vector>
#include<set>
using namespace std;
vector<int> path;
int a[209][209]={0};
bool cflag=true;
void dfs(vector<int>path1)
{//end 判断这个部分图是否连通 
for(int i=1;i<path1.size();i++)
 {  if(a[path1[i-1]][path[i]]==0)
      cflag=false; 
  }
}
int main()
{int n,m,ll,rr,tempk,kk;
cin>>n>>m;
for(int i=0;i<m;i++)
   {
   cin>>ll>>rr;
   a[ll][rr]=a[rr][ll]=1;
   }
cin>>tempk;
for(int i=0;i<tempk;i++)
  { cin>>kk;
  cflag=true;
  set<int>sett;
  path.clear();
  path.resize(kk);
  for(int j=0;j<kk;j++)
  {
  scanf("%d",&path[j]);
  sett.insert(path[j]);
  }
  dfs(path);
  if(path[0]!=path[kk-1]||cflag==false) printf("NO\n");//begin end 到底指向啥 
  else if(sett.size()!=n) printf("NO\n");
  else if(kk!=n+1) printf("NO\n");//简单的图包含每个顶点形成环其中只能一共有n+1个点 
  else printf("YES\n");
}
return 0;
}

to sum up

1. Note that the simple ring contains every vertex, and it can only be n+1 vertices if it is not repeated

2. The end() of vector does not point to the last element, but the next position of the last element, so if you take the last element, you cannot use c.end()

English

problem

no

 

Guess you like

Origin blog.csdn.net/m0_45359314/article/details/112834909