이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize "-O3"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1e5 + 1;
vector<int> g[N];
int n, m;
int X, S, A, B;
int d[N];
int bfs(int s) {
queue<int> q;
for(int i = 1 ; i <= n ; ++i)
d[i] = N;
d[s] = 0; q.push(s);
while(q.size()) {
int u = q.front(); q.pop();
for(int v : g[u])
if (d[v] > d[u] + 1) {
d[v] = d[u] + 1;
q.push(v);
}
}
if (d[X] > d[S]) {
puts("-1");
exit(0);
}
return d[S] - d[X];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("SPY.inp","r",stdin);
//freopen("SPY.out","w",stdout);
cin >> n >> m >> X >> S >> A >> B;
while(m--) {
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
cout << min(bfs(A),bfs(B));
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |