# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
246174 | mieszko11b | 007 (CEOI14_007) | C++14 | 303 ms | 23032 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;
int n, m;
int s, d, a, b;
vector<int> G[200007];
int dist[200007];
bool vis[200007];
void run_bfs(int w) {
memset(vis, 0, sizeof vis);
vis[w] = 1;
dist[w] = 0;
queue<int> Q;
Q.push(w);
while(!Q.empty()) {
int u= Q.front();
Q.pop();
for(int v : G[u]) {
if(!vis[v]) {
vis[v] = 1;
dist[v] = dist[u] + 1;
Q.push(v);
}
}
}
}
int main() {
scanf("%d%d%d%d%d%d", &n, &m, &s, &d, &a, &b);
while(m--) {
int a, b;
scanf("%d%d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
run_bfs(s);
int sa = dist[a], sb = dist[b];
run_bfs(d);
int da = dist[a], db = dist[b];
int val = min(da - sa, db - sb);
if(val < 0) val = 0;
printf("%d\n", val - 1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |