답안 #90799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90799 2018-12-24T13:06:31 Z FutymyClone 007 (CEOI14_007) C++14
0 / 100
330 ms 18420 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n, m, s, d, a, b, ans1 = 0, ans2 = 0, d1[N], d2[N], d3[N], d4[N];
vector <int> g[N];

void bfs1(){
    memset(d1, 0x3f, sizeof(d1)); queue <int> q;
    d1[a] = 0; q.push(a);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto v: g[u]) {
            if (d1[v] > d1[u] + 1) {
                d1[v] = d1[u] + 1;
                q.push(v);
            }
        }
    }
}

void bfs2(){
    memset(d2, 0x3f, sizeof(d2)); queue <int> q;
    d2[b] = 0; q.push(b);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto v: g[u]) {
            if (d2[v] > d2[u] + 1) {
                d2[v] = d2[u] + 1;
                q.push(v);
            }
        }
    }
}

void bfs3(){
    memset(d3, 0x3f, sizeof(d3));
    queue <int> q; q.push(s); d3[s] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        ans1 = max(ans1, d3[u]);
        for (auto v: g[u]) {
            if (d3[v] > 1e9 && (d1[v] == d1[u] - 1 || d2[v] == d2[u] - 1)) {
                d3[v] = d3[u] + 1;
                q.push(v);
            }
        }
    }
}

void bfs4(){
    memset(d4, 0x3f, sizeof(d4));
    queue <int> q; q.push(d); d4[d] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        ans2 = max(ans2, d4[u]);
        for (auto v: g[u]) {
            if (d4[v] > 1e9 && (d1[v] == d1[u] - 1 && d2[v] == d2[u] - 1)) {
                d4[v] = d4[u] + 1;
                q.push(v);
            }
        }
    }
}

int main(){
    scanf("%d %d", &n, &m);
    scanf("%d %d %d %d", &s, &d, &a, &b);
    for (int i = 1; i <= m; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].push_back(v); g[v].push_back(u);
    }

    bfs1(); bfs2();
    if (d1[d] - d1[s] != d2[d] - d2[s]) printf("%d", max(min(d1[d] - d1[s], d2[d] - d2[s]), -1));
    else {
        bfs3(); bfs4();
        printf("%d", max(d1[d] - d1[s] - ((d1[d] - d1[s] + ans1) < ans2), -1));
    }
    return 0;
}
/*
6 6
1 2 3 4
1 5
5 6
6 3
6 4
1 2
3 4

6 7
5 6 1 2
6 3
1 2
1 3
2 3
1 5
2 4
5 4
*/

Compilation message

007.cpp: In function 'int main()':
007.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
007.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &s, &d, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6520 KB Output is correct
2 Correct 8 ms 8180 KB Output is correct
3 Correct 8 ms 8216 KB Output is correct
4 Incorrect 8 ms 8340 KB Output isn't correct
5 Incorrect 8 ms 8340 KB Output isn't correct
6 Correct 8 ms 8452 KB Output is correct
7 Correct 8 ms 8452 KB Output is correct
8 Incorrect 8 ms 8452 KB Output isn't correct
9 Correct 8 ms 8452 KB Output is correct
10 Correct 7 ms 8452 KB Output is correct
11 Correct 7 ms 8452 KB Output is correct
12 Incorrect 8 ms 8452 KB Output isn't correct
13 Correct 8 ms 8452 KB Output is correct
14 Incorrect 8 ms 8452 KB Output isn't correct
15 Correct 8 ms 8452 KB Output is correct
16 Incorrect 9 ms 8552 KB Output isn't correct
17 Incorrect 8 ms 8552 KB Output isn't correct
18 Incorrect 8 ms 8552 KB Output isn't correct
19 Correct 8 ms 8552 KB Output is correct
20 Correct 8 ms 8552 KB Output is correct
21 Correct 7 ms 8552 KB Output is correct
22 Correct 8 ms 8552 KB Output is correct
23 Correct 8 ms 8552 KB Output is correct
24 Incorrect 9 ms 8552 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 9724 KB Output is correct
2 Incorrect 35 ms 10236 KB Output isn't correct
3 Correct 30 ms 10236 KB Output is correct
4 Incorrect 38 ms 10364 KB Output isn't correct
5 Correct 27 ms 10364 KB Output is correct
6 Correct 28 ms 10364 KB Output is correct
7 Correct 31 ms 10364 KB Output is correct
8 Correct 32 ms 10364 KB Output is correct
9 Incorrect 48 ms 10364 KB Output isn't correct
10 Correct 163 ms 14588 KB Output is correct
11 Incorrect 63 ms 14588 KB Output isn't correct
12 Correct 92 ms 14588 KB Output is correct
13 Incorrect 58 ms 14588 KB Output isn't correct
14 Correct 47 ms 14588 KB Output is correct
15 Correct 72 ms 14588 KB Output is correct
16 Correct 73 ms 14588 KB Output is correct
17 Correct 61 ms 14588 KB Output is correct
18 Incorrect 66 ms 14588 KB Output isn't correct
19 Correct 121 ms 14588 KB Output is correct
20 Incorrect 217 ms 15864 KB Output isn't correct
21 Incorrect 90 ms 15864 KB Output isn't correct
22 Correct 104 ms 15864 KB Output is correct
23 Correct 187 ms 15864 KB Output is correct
24 Correct 91 ms 15864 KB Output is correct
25 Incorrect 91 ms 15864 KB Output isn't correct
26 Correct 75 ms 15864 KB Output is correct
27 Correct 88 ms 15864 KB Output is correct
28 Correct 106 ms 15864 KB Output is correct
29 Correct 161 ms 15864 KB Output is correct
30 Incorrect 330 ms 16468 KB Output isn't correct
31 Incorrect 137 ms 16468 KB Output isn't correct
32 Correct 126 ms 16468 KB Output is correct
33 Correct 114 ms 16468 KB Output is correct
34 Incorrect 147 ms 16468 KB Output isn't correct
35 Incorrect 117 ms 16468 KB Output isn't correct
36 Incorrect 128 ms 16468 KB Output isn't correct
37 Correct 110 ms 16468 KB Output is correct
38 Correct 115 ms 16468 KB Output is correct
39 Correct 138 ms 16468 KB Output is correct
40 Incorrect 187 ms 16468 KB Output isn't correct
41 Correct 312 ms 18420 KB Output is correct