# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101446 | cheeheng | 007 (CEOI14_007) | C++14 | 393 ms | 15932 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 <bits/stdc++.h>
using namespace std;
vector<int> AdjList[200005];
int dist[200005];
int main(){
int N, M;
int s, d, a, b;
scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b);
for(int i = 0; i < M; i ++){
int x, y;
scanf("%d%d", &x, &y);
AdjList[x].push_back(y);
AdjList[y].push_back(x);
}
memset(dist, -1, sizeof(dist));
queue<int> q;
q.push(s);
dist[s] = 0;
while(!q.empty()){
int u = q.front(); q.pop();
for(int v: AdjList[u]){
if(dist[v] == -1){
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
int sa = dist[a];
int sb = dist[b];
memset(dist, -1, sizeof(dist));
q = queue<int>();
q.push(d);
dist[d] = 0;
while(!q.empty()){
int u = q.front(); q.pop();
for(int v: AdjList[u]){
if(dist[v] == -1){
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
int da = dist[a];
int db = dist[b];
//printf("%d %d %d %d\n", sa, sb, da, db);
int resA = min(da-sa, db-sa-1);
int resB = min(da-sb-1, da-sb);
int res = max(resA, resB);
int ans = max(res, -1);
printf("%d", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |