답안 #793336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793336 2023-07-25T17:59:55 Z Valaki2 007 (CEOI14_007) C++14
0 / 100
162 ms 17452 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int maxn = 2e5;

int n, m;
vector<int> graph[1 + maxn];
int g, s, a, b;
vector<int> dg, ds, da, db;

vector<int> bfs(int start) {
    vector<int> res(1 + n, -1);
    res[start] = 0;
    queue<int> q;
    q.push(start);
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        for(int nei : graph[cur]) {
            if(res[nei] == -1) {
                res[nei] = res[cur] + 1;
                q.push(nei);
            }
        }
    }
    return res;
}

void solve() {
    cin >> n >> m;
    cin >> g >> s >> a >> b;
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        graph[x].pb(y);
        graph[y].pb(x);
    }
    dg = bfs(g), ds = bfs(s), da = bfs(a), db = bfs(b);
    if((da[s] < da[g]) || (db[s] < db[g])) {
        cout << "-1\n";
        return;
    }
    int add_a = da[s] - 1 - da[g], add_b = db[s] - 1 - db[g];
    bool extra_case = true;
    if(add_a != add_b) {
        add_a++, add_b++;
        extra_case = false;
    }
    int to_add = min(add_a, add_b);
    if(!extra_case) {
        cout << to_add << "\n";
        return;
    }
    cout << 0 << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Incorrect 2 ms 4948 KB Output isn't correct
7 Incorrect 2 ms 4948 KB Output isn't correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 2 ms 4948 KB Output isn't correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Incorrect 2 ms 4948 KB Output isn't correct
13 Incorrect 2 ms 4948 KB Output isn't correct
14 Incorrect 2 ms 4948 KB Output isn't correct
15 Incorrect 2 ms 4948 KB Output isn't correct
16 Incorrect 2 ms 4948 KB Output isn't correct
17 Incorrect 2 ms 4948 KB Output isn't correct
18 Incorrect 2 ms 4948 KB Output isn't correct
19 Incorrect 2 ms 4948 KB Output isn't correct
20 Incorrect 2 ms 5024 KB Output isn't correct
21 Correct 2 ms 4948 KB Output is correct
22 Incorrect 2 ms 4948 KB Output isn't correct
23 Incorrect 3 ms 4948 KB Output isn't correct
24 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 6912 KB Output isn't correct
2 Incorrect 18 ms 7764 KB Output isn't correct
3 Incorrect 15 ms 7008 KB Output isn't correct
4 Incorrect 18 ms 7824 KB Output isn't correct
5 Correct 14 ms 6740 KB Output is correct
6 Correct 14 ms 7124 KB Output is correct
7 Incorrect 19 ms 7312 KB Output isn't correct
8 Incorrect 16 ms 7320 KB Output isn't correct
9 Incorrect 24 ms 7764 KB Output isn't correct
10 Incorrect 90 ms 12156 KB Output isn't correct
11 Incorrect 29 ms 9164 KB Output isn't correct
12 Incorrect 43 ms 10264 KB Output isn't correct
13 Incorrect 33 ms 9612 KB Output isn't correct
14 Correct 26 ms 8824 KB Output is correct
15 Incorrect 35 ms 10444 KB Output isn't correct
16 Correct 38 ms 10700 KB Output is correct
17 Incorrect 31 ms 10068 KB Output isn't correct
18 Incorrect 37 ms 10096 KB Output isn't correct
19 Incorrect 59 ms 11260 KB Output isn't correct
20 Incorrect 113 ms 14088 KB Output isn't correct
21 Incorrect 51 ms 12492 KB Output isn't correct
22 Incorrect 64 ms 11544 KB Output isn't correct
23 Incorrect 46 ms 12376 KB Output isn't correct
24 Incorrect 45 ms 12364 KB Output isn't correct
25 Incorrect 45 ms 11976 KB Output isn't correct
26 Incorrect 41 ms 11592 KB Output isn't correct
27 Incorrect 47 ms 12492 KB Output isn't correct
28 Incorrect 54 ms 12516 KB Output isn't correct
29 Incorrect 77 ms 12908 KB Output isn't correct
30 Incorrect 121 ms 14868 KB Output isn't correct
31 Incorrect 57 ms 13640 KB Output isn't correct
32 Incorrect 60 ms 12428 KB Output isn't correct
33 Incorrect 52 ms 12640 KB Output isn't correct
34 Incorrect 59 ms 13048 KB Output isn't correct
35 Incorrect 50 ms 12744 KB Output isn't correct
36 Incorrect 49 ms 12996 KB Output isn't correct
37 Correct 63 ms 14108 KB Output is correct
38 Incorrect 60 ms 13888 KB Output isn't correct
39 Incorrect 65 ms 13896 KB Output isn't correct
40 Incorrect 115 ms 15492 KB Output isn't correct
41 Incorrect 162 ms 17452 KB Output isn't correct