Submission #82362

# Submission time Handle Problem Language Result Execution time Memory
82362 2018-10-30T09:49:14 Z FutymyClone 007 (CEOI14_007) C++14
0 / 100
10 ms 6940 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n, m, s, d, a, b, dist[2][N];
vector <int> g[N];
queue <int> q;

void bfs (int type){
    if (!type) memset(dist, 0x3f, sizeof(dist));
    dist[type][(type == 0) ? d : s] = 0;
    q.push((type == 0) ? d : s);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto v: g[u]) {
            if (type == 0 && v == s) continue;
            if (dist[type][v] > dist[type][u] + 1) {
                dist[type][v] = dist[type][u] + 1;
                q.push(v);
            }
        }
    }
}

int main(){
    #ifndef Futymy
        freopen("SPY.inp", "r", stdin);
        freopen("SPY.out", "w", stdout);
    #endif // Futymy
    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);
    }

    bfs(0); bfs(1);
    //for (int i = 1; i <= n; i++) cout << dist[0][i] << " ";
    //cout << "\n";
    int Min = min(dist[0][a], dist[0][b]);
    //cout << dist[0][a] << " " << dist[0][b] << "\n";
    if (Min > 1e9) printf("%d", dist[1][d]);
    else {
        if (dist[0][a] < 1e9 && dist[0][b] > 1e9) {
            if (dist[1][a] > dist[0][a]) printf("%d", -1);
            else printf("%d", min(dist[1][d], dist[0][a] - dist[1][a]));
        }
        else if (dist[0][a] > 1e9 && dist[0][b] < 1e9) {
            if (dist[1][b] > dist[0][b]) printf("%d", -1);
            else printf("%d", min(dist[1][d], dist[0][b] - dist[1][b]));
        }
        else {
            if (dist[1][b] > dist[0][b] || dist[1][a] > dist[0][a]) printf("%d", -1);
            else printf("%d", min(dist[0][a] - dist[1][a], dist[0][b] - dist[1][b]));
        }
    }
    return 0;
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("SPY.inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
007.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("SPY.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:32: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:33: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:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 6520 KB Unexpected end of file - int64 expected
2 Incorrect 7 ms 6644 KB Unexpected end of file - int64 expected
3 Incorrect 7 ms 6684 KB Unexpected end of file - int64 expected
4 Incorrect 8 ms 6764 KB Unexpected end of file - int64 expected
5 Incorrect 7 ms 6764 KB Unexpected end of file - int64 expected
6 Incorrect 7 ms 6764 KB Unexpected end of file - int64 expected
7 Incorrect 7 ms 6764 KB Unexpected end of file - int64 expected
8 Incorrect 8 ms 6764 KB Unexpected end of file - int64 expected
9 Incorrect 8 ms 6764 KB Unexpected end of file - int64 expected
10 Incorrect 7 ms 6764 KB Unexpected end of file - int64 expected
11 Incorrect 7 ms 6764 KB Unexpected end of file - int64 expected
12 Incorrect 8 ms 6812 KB Unexpected end of file - int64 expected
13 Incorrect 8 ms 6824 KB Unexpected end of file - int64 expected
14 Incorrect 7 ms 6824 KB Unexpected end of file - int64 expected
15 Incorrect 9 ms 6824 KB Unexpected end of file - int64 expected
16 Incorrect 8 ms 6824 KB Unexpected end of file - int64 expected
17 Incorrect 8 ms 6824 KB Unexpected end of file - int64 expected
18 Incorrect 7 ms 6824 KB Unexpected end of file - int64 expected
19 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
20 Incorrect 9 ms 6868 KB Unexpected end of file - int64 expected
21 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
22 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
23 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
24 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
2 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
3 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
4 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
5 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
6 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
7 Incorrect 10 ms 6868 KB Unexpected end of file - int64 expected
8 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
9 Incorrect 9 ms 6868 KB Unexpected end of file - int64 expected
10 Incorrect 10 ms 6868 KB Unexpected end of file - int64 expected
11 Incorrect 10 ms 6868 KB Unexpected end of file - int64 expected
12 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
13 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
14 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
15 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
16 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
17 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
18 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
19 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
20 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
21 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
22 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
23 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
24 Incorrect 9 ms 6868 KB Unexpected end of file - int64 expected
25 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
26 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
27 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
28 Incorrect 8 ms 6868 KB Unexpected end of file - int64 expected
29 Incorrect 9 ms 6868 KB Unexpected end of file - int64 expected
30 Incorrect 9 ms 6868 KB Unexpected end of file - int64 expected
31 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
32 Incorrect 7 ms 6868 KB Unexpected end of file - int64 expected
33 Incorrect 8 ms 6940 KB Unexpected end of file - int64 expected
34 Incorrect 8 ms 6940 KB Unexpected end of file - int64 expected
35 Incorrect 7 ms 6940 KB Unexpected end of file - int64 expected
36 Incorrect 7 ms 6940 KB Unexpected end of file - int64 expected
37 Incorrect 8 ms 6940 KB Unexpected end of file - int64 expected
38 Incorrect 8 ms 6940 KB Unexpected end of file - int64 expected
39 Incorrect 7 ms 6940 KB Unexpected end of file - int64 expected
40 Incorrect 7 ms 6940 KB Unexpected end of file - int64 expected
41 Incorrect 7 ms 6940 KB Unexpected end of file - int64 expected