# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
668539 | RambaXGorilla | 007 (CEOI14_007) | C++17 | 220 ms | 22284 KiB |
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<cstdio>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
using namespace std;
typedef pair <int,int> ii;
int N, M, S, D, A, B;
vector <int> adj[200010];
queue <ii> near;
bool vis[200010] = {};
ii bfs(int X){
ii servers;
near.push(ii(X, 0));
while(!near.empty()){
int node = near.front().first;
int dist = near.front().second;
near.pop();
if(vis[node]) continue;
vis[node] = true;
if(node == A) servers.first = dist;
else if(node == B) servers.second = dist;
for(int i : adj[node]){
near.push(ii(i, dist + 1));
}
}
fill(vis, vis + 200010, false);
return servers;
}
int main(){
scanf("%d%d%d%d%d%d",&N,&M,&S,&D,&A,&B);
for(int i = 0;i < M;i++){
int a, b;
scanf("%d%d",&a,&b);
adj[a].push_back(b);
adj[b].push_back(a);
}
ii agent = bfs(S);
ii doctor = bfs(D);
printf("%d",max(min(doctor.first - agent.first, doctor.second - agent.second), -1));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |