This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 5;
int n, m, s, v, a, b, ds[mx], dd[mx], da[mx], db[mx]; vector<int> adj[mx];
int bfs(int st, int en){
queue<int> Q; int D[n + 1]; fill(D, D + n + 1, -1);
Q.push(st); D[st] = 0;
while (!Q.empty()){
int i = Q.front(); Q.pop();
if (i == en) return D[i];
for (int j : adj[i]) if (D[j] == -1) D[j] = D[i] + 1, Q.push(j);
}
}
int main(){
cin >> n >> m >> s >> v >> a >> b;
for (int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
adj[a].push_back(b); adj[b].push_back(a);
}
cout<<max(min(bfs(v, a) - bfs(s, a), bfs(v, b) - bfs(s, b)), -1)<<endl;
}
Compilation message (stderr)
007.cpp: In function 'int bfs(int, int)':
007.cpp:9:16: warning: control reaches end of non-void function [-Wreturn-type]
9 | queue<int> Q; int D[n + 1]; fill(D, D + n + 1, -1);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |