답안 #257824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257824 2020-08-04T22:02:45 Z doowey 007 (CEOI14_007) C++14
0 / 100
365 ms 24968 KB
#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]);
            }
        }
        if(cc + d0 >= dd){
            cout << max(-1,d0) << "\n";
        }
        else{
            cout << max(-1,d0-1) << "\n";
        }
    }
    return 0;
}

Compilation message

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]){
                                                           ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Partially correct 3 ms 4992 KB Partially correct
3 Correct 3 ms 4992 KB Output is correct
4 Incorrect 3 ms 4992 KB Output isn't correct
5 Incorrect 3 ms 4992 KB Output isn't correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Incorrect 3 ms 4992 KB Output isn't correct
9 Correct 3 ms 5120 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Incorrect 5 ms 5120 KB Output isn't correct
13 Correct 4 ms 5120 KB Output is correct
14 Incorrect 3 ms 4992 KB Output isn't correct
15 Correct 4 ms 5120 KB Output is correct
16 Incorrect 4 ms 5120 KB Output isn't correct
17 Incorrect 3 ms 5120 KB Output isn't correct
18 Incorrect 3 ms 5120 KB Output isn't correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 3 ms 5120 KB Output is correct
21 Incorrect 3 ms 5120 KB Output isn't correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Incorrect 4 ms 5120 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 7544 KB Output is correct
2 Incorrect 36 ms 8576 KB Output isn't correct
3 Correct 28 ms 7552 KB Output is correct
4 Incorrect 38 ms 8704 KB Output isn't correct
5 Correct 32 ms 7416 KB Output is correct
6 Correct 41 ms 7680 KB Output is correct
7 Correct 39 ms 7936 KB Output is correct
8 Correct 40 ms 7936 KB Output is correct
9 Incorrect 54 ms 8824 KB Output isn't correct
10 Correct 163 ms 17400 KB Output is correct
11 Incorrect 76 ms 10360 KB Output isn't correct
12 Correct 90 ms 11832 KB Output is correct
13 Incorrect 75 ms 10872 KB Output isn't correct
14 Correct 55 ms 9848 KB Output is correct
15 Correct 83 ms 11896 KB Output is correct
16 Correct 93 ms 12280 KB Output is correct
17 Correct 95 ms 11512 KB Output is correct
18 Incorrect 84 ms 11512 KB Output isn't correct
19 Correct 124 ms 13944 KB Output is correct
20 Incorrect 214 ms 19832 KB Output isn't correct
21 Incorrect 204 ms 14584 KB Output isn't correct
22 Correct 120 ms 13304 KB Output is correct
23 Correct 159 ms 14456 KB Output is correct
24 Correct 162 ms 14328 KB Output is correct
25 Incorrect 133 ms 14116 KB Output isn't correct
26 Correct 117 ms 13408 KB Output is correct
27 Correct 168 ms 14584 KB Output is correct
28 Correct 182 ms 14584 KB Output is correct
29 Correct 160 ms 16352 KB Output is correct
30 Incorrect 242 ms 20984 KB Output isn't correct
31 Incorrect 149 ms 15992 KB Output isn't correct
32 Correct 180 ms 14456 KB Output is correct
33 Correct 177 ms 14840 KB Output is correct
34 Incorrect 182 ms 15352 KB Output isn't correct
35 Incorrect 144 ms 14840 KB Output isn't correct
36 Incorrect 149 ms 15352 KB Output isn't correct
37 Correct 206 ms 16760 KB Output is correct
38 Correct 180 ms 16508 KB Output is correct
39 Correct 196 ms 16504 KB Output is correct
40 Incorrect 252 ms 19960 KB Output isn't correct
41 Correct 365 ms 24968 KB Output is correct