CSP 5-7 valid 有效的BFS

AC on both CG and Codeforces
This commit is contained in:
cyp0633 2021-07-30 08:40:01 +08:00
parent 51e240b5e2
commit 17ac94f962
1 changed files with 6 additions and 9 deletions

View File

@ -45,21 +45,18 @@ int main()
} }
} }
childNum = childSet.size(); childNum = childSet.size();
for (int i = 0; i < childNum; i++) //或许并不应该这样做? for (int i = 0; i < childNum; i++)
{ {
it = find(G[currPos].begin(), G[currPos].end(), reqSeq.front()); set<int>::iterator it = childSet.find(reqSeq.front());
if (it != G[currPos].end()) //存在此儿子 if (it == childSet.end())
{
visitSeq.emplace(reqSeq.front());
reqSeq.pop();
}
else
{ {
printf("No"); printf("No");
return 0; return 0;
} }
childSet.clear(); //清空儿子集合 visitSeq.emplace(reqSeq.front());
reqSeq.pop();
} }
childSet.clear(); //清空儿子集合
} }
printf("Yes"); printf("Yes");
return 0; return 0;