이 제출은 이전 버전의 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 + 1){
cout << max(-1,d1) << "\n";
}
else if(d1 == d0 + 1){
cout << max(-1,d0) << "\n";
}
else{
int cc = 0;
int dd = 0;
for(int i = 1; i <= n; i ++ ){
if(d[0][i] + d[3][i] == d[0][n0] && d[0][i] + d[4][i] == d[0][n1]){
cc = max(cc, d[0][i]);
}
if(d[1][i] + d[3][i] == d[1][n0] && d[1][i] + d[4][i] == d[1][n1]){
dd = max(dd, d[1][i]);
}
}
cout << max(-1,d0-1) << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
007.cpp: In function 'int main()':
007.cpp:69:62: warning: array subscript is above array bounds [-Warray-bounds]
if(d[0][i] + d[3][i] == d[0][n0] && d[0][i] + d[4][i] == d[0][n1]){
~~~^
007.cpp:72:62: warning: array subscript is above array bounds [-Warray-bounds]
if(d[1][i] + d[3][i] == d[1][n0] && d[1][i] + d[4][i] == d[1][n1]){
~~~^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |