Submission #101517

# Submission time Handle Problem Language Result Execution time Memory
101517 2019-03-19T03:32:35 Z cheeheng 007 (CEOI14_007) C++14
0 / 100
345 ms 15612 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> AdjList[200005];
int dist[200005];

int main(){
    int N, M;
    int s, d, a, b;
    scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b);

    for(int i = 0; i < M; i ++){
        int x, y;
        scanf("%d%d", &x, &y);
        AdjList[x].push_back(y);
        AdjList[y].push_back(x);
    }

    memset(dist, -1, sizeof(dist));
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v: AdjList[u]){
            if(dist[v] == -1){
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }

    int sa = dist[a];
    int sb = dist[b];

    memset(dist, -1, sizeof(dist));
    q = queue<int>();
    q.push(d);
    dist[d] = 0;
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v: AdjList[u]){
            if(dist[v] == -1){
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }

    int da = dist[a];
    int db = dist[b];

    //printf("%d %d %d %d\n", sa, sb, da, db);

    int resA = min(da-sa, db-sa-1);
    int resB = min(da-sb-1, da-sb);
    int res = max(resA, resB);
    int ans = max(res, -1);
    if(db-sa-1 == da-sb-1){
        ans ++;
    }
    printf("%d", ans);
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5888 KB Output is correct
2 Correct 7 ms 5760 KB Output is correct
3 Correct 8 ms 5760 KB Output is correct
4 Incorrect 7 ms 5888 KB Output isn't correct
5 Incorrect 8 ms 5888 KB Output isn't correct
6 Correct 8 ms 5760 KB Output is correct
7 Correct 9 ms 5888 KB Output is correct
8 Incorrect 7 ms 5888 KB Output isn't correct
9 Correct 8 ms 5888 KB Output is correct
10 Correct 7 ms 5888 KB Output is correct
11 Correct 7 ms 5760 KB Output is correct
12 Incorrect 7 ms 5760 KB Output isn't correct
13 Correct 7 ms 5760 KB Output is correct
14 Incorrect 8 ms 5760 KB Output isn't correct
15 Correct 8 ms 5760 KB Output is correct
16 Incorrect 7 ms 5760 KB Output isn't correct
17 Incorrect 8 ms 5916 KB Output isn't correct
18 Incorrect 8 ms 5808 KB Output isn't correct
19 Correct 7 ms 5760 KB Output is correct
20 Correct 9 ms 5760 KB Output is correct
21 Incorrect 8 ms 5760 KB Output isn't correct
22 Correct 8 ms 5760 KB Output is correct
23 Correct 9 ms 5760 KB Output is correct
24 Incorrect 8 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7136 KB Output is correct
2 Incorrect 61 ms 7672 KB Output isn't correct
3 Correct 40 ms 7160 KB Output is correct
4 Incorrect 73 ms 7776 KB Output isn't correct
5 Incorrect 42 ms 7032 KB Output isn't correct
6 Incorrect 33 ms 7168 KB Output isn't correct
7 Correct 39 ms 7480 KB Output is correct
8 Correct 39 ms 7264 KB Output is correct
9 Incorrect 84 ms 7804 KB Output isn't correct
10 Correct 233 ms 12024 KB Output is correct
11 Incorrect 67 ms 8568 KB Output isn't correct
12 Correct 143 ms 9336 KB Output is correct
13 Incorrect 85 ms 8824 KB Output isn't correct
14 Incorrect 82 ms 8440 KB Output isn't correct
15 Correct 116 ms 9464 KB Output is correct
16 Incorrect 98 ms 9540 KB Output isn't correct
17 Correct 87 ms 9208 KB Output is correct
18 Incorrect 83 ms 9208 KB Output isn't correct
19 Correct 140 ms 10360 KB Output is correct
20 Incorrect 254 ms 13180 KB Output isn't correct
21 Incorrect 144 ms 10892 KB Output isn't correct
22 Correct 133 ms 10104 KB Output is correct
23 Correct 152 ms 10844 KB Output is correct
24 Correct 118 ms 10744 KB Output is correct
25 Incorrect 147 ms 10588 KB Output isn't correct
26 Correct 137 ms 10232 KB Output is correct
27 Correct 144 ms 10872 KB Output is correct
28 Correct 154 ms 10816 KB Output is correct
29 Correct 207 ms 11640 KB Output is correct
30 Incorrect 304 ms 13784 KB Output isn't correct
31 Incorrect 159 ms 11640 KB Output isn't correct
32 Correct 150 ms 10776 KB Output is correct
33 Correct 130 ms 10992 KB Output is correct
34 Incorrect 151 ms 11212 KB Output isn't correct
35 Incorrect 205 ms 11132 KB Output isn't correct
36 Incorrect 138 ms 11132 KB Output isn't correct
37 Incorrect 153 ms 11856 KB Output isn't correct
38 Correct 160 ms 11768 KB Output is correct
39 Correct 171 ms 11896 KB Output is correct
40 Incorrect 230 ms 13460 KB Output isn't correct
41 Correct 345 ms 15612 KB Output is correct