이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)2e5 + 10;
vector<int> T[N];
int c = 0;
int d[4][N];
int n;
void bfs(int node){
for(int i = 1; i <= n; i ++ )
d[c][i] = (int)1e9;
queue<int> bf;
bf.push(node);
d[c][node] = 0;
while(!bf.empty()){
node = bf.front();
bf.pop();
for(auto x : T[node]){
if(d[c][x] > d[c][node] + 1){
d[c][x] = d[c][node] + 1;
bf.push(x);
}
}
}
c ++ ;
}
int main(){
fastIO;
int m;
cin >> n >> m;
int a, b;
cin >> a >> b;
int n0, n1;
cin >> n0 >> n1;
int u, v;
for(int i = 0 ; i < m ; i ++ ){
cin >> u >> v;
T[u].push_back(v);
T[v].push_back(u);
}
bfs(a);
bfs(b);
bfs(n0);
bfs(n1);
int d0 = d[1][n0] - d[0][n0];
int d1 = d[1][n1] - d[0][n1];
if(d0 != d1){
int low = min(d0,d1);
if(low < 0) cout << -1 << "\n";
else cout << low << "\n";
return 0;
}
cout << max(-1,min(d0,d1)-1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |