답안 #101522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101522 2019-03-19T03:36:58 Z cheeheng 007 (CEOI14_007) C++14
9 / 100
366 ms 15608 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);
    if(db-sa-1 == da-sa){
        resA ++;
    }
    int res = max(resA, resB);
    int ans = max(res, -1);

    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);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5760 KB Output is correct
2 Correct 8 ms 5888 KB Output is correct
3 Partially correct 7 ms 5760 KB Partially correct
4 Correct 8 ms 5760 KB Output is correct
5 Correct 8 ms 5888 KB Output is correct
6 Partially correct 7 ms 5760 KB Partially correct
7 Partially correct 8 ms 5888 KB Partially correct
8 Correct 7 ms 5760 KB Output is correct
9 Partially correct 7 ms 5760 KB Partially correct
10 Correct 8 ms 5760 KB Output is correct
11 Correct 8 ms 5760 KB Output is correct
12 Correct 8 ms 5888 KB Output is correct
13 Partially correct 7 ms 5860 KB Partially correct
14 Correct 7 ms 5760 KB Output is correct
15 Partially correct 7 ms 5760 KB Partially correct
16 Correct 9 ms 5760 KB Output is correct
17 Correct 7 ms 5760 KB Output is correct
18 Correct 8 ms 5888 KB Output is correct
19 Partially correct 7 ms 5760 KB Partially correct
20 Partially correct 7 ms 5760 KB Partially correct
21 Correct 8 ms 5760 KB Output is correct
22 Partially correct 7 ms 5936 KB Partially correct
23 Partially correct 7 ms 5888 KB Partially correct
24 Correct 9 ms 5888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 30 ms 7040 KB Partially correct
2 Correct 54 ms 7672 KB Output is correct
3 Partially correct 32 ms 7296 KB Partially correct
4 Correct 50 ms 7672 KB Output is correct
5 Incorrect 46 ms 7032 KB Output isn't correct
6 Incorrect 37 ms 7160 KB Output isn't correct
7 Partially correct 39 ms 7288 KB Partially correct
8 Partially correct 40 ms 7288 KB Partially correct
9 Correct 56 ms 7672 KB Output is correct
10 Partially correct 192 ms 11896 KB Partially correct
11 Correct 62 ms 8600 KB Output is correct
12 Partially correct 93 ms 9336 KB Partially correct
13 Correct 76 ms 8924 KB Output is correct
14 Correct 58 ms 8440 KB Output is correct
15 Partially correct 85 ms 9464 KB Partially correct
16 Incorrect 91 ms 9744 KB Output isn't correct
17 Partially correct 79 ms 9208 KB Partially correct
18 Correct 82 ms 9336 KB Output is correct
19 Partially correct 128 ms 10332 KB Partially correct
20 Correct 318 ms 13176 KB Output is correct
21 Correct 188 ms 10988 KB Output is correct
22 Partially correct 111 ms 10196 KB Partially correct
23 Incorrect 158 ms 10744 KB Output isn't correct
24 Partially correct 127 ms 10744 KB Partially correct
25 Correct 127 ms 10528 KB Output is correct
26 Incorrect 158 ms 10212 KB Output isn't correct
27 Partially correct 139 ms 10876 KB Partially correct
28 Partially correct 170 ms 10872 KB Partially correct
29 Partially correct 216 ms 11684 KB Partially correct
30 Correct 276 ms 13688 KB Output is correct
31 Correct 168 ms 11640 KB Output is correct
32 Partially correct 147 ms 10896 KB Partially correct
33 Correct 125 ms 11000 KB Output is correct
34 Correct 181 ms 11128 KB Output is correct
35 Correct 141 ms 11128 KB Output is correct
36 Correct 154 ms 11220 KB Output is correct
37 Incorrect 153 ms 12024 KB Output isn't correct
38 Partially correct 160 ms 11768 KB Partially correct
39 Partially correct 204 ms 11768 KB Partially correct
40 Correct 265 ms 13432 KB Output is correct
41 Partially correct 366 ms 15608 KB Partially correct