先有一份代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
basic_string<int>g[111111];
queue<pair<int,int>>q;
int s,t;
// bitset<111111>vis[4];
bool vis[111111][4];
signed main()
{
// freopen("min_dis.in","r",stdin);
// freopen("min_dis.out","w",stdout);
cin>>n>>m;
for(int i=1,x,y;i<=m;i++)
{
cin>>x>>y;
g[x]+=y;
}
cin>>s>>t;
vis[s][0]=1;
q.push({s,0});
while(!q.empty())
{
pair<int,int>tt=q.front();
q.pop();
tt.second++;
for(int v:g[tt.first])
{
if(!vis[v][tt.second%3])
{
if(v==t and tt.second%3==0)
{
cout<<tt.second/3;
return 0;
}
vis[v][tt.second%3]=1;
q.emplace(v,tt.second);
}
}
}
puts("-1");
}
样例
6 8
1 2
2 3
3 4
4 5
5 1
1 4
1 5
4 6
1 6
用bitset的RE,用bool的AC,为什么