如果你的提交记录是这样
那么只需要在你的 spfa 中加上:
int tot=0; while(q.size()){ tot++; if(tot>1e7){ find_answer=1; cout<<-1; return; }
你就可以AC了
显然这种做法在比赛时比较看 rp,建议能打正解还是打正解。