Submission #101404

# Submission time Handle Problem Language Result Execution time Memory
101404 2019-03-19T01:01:46 Z rocketninja7 007 (CEOI14_007) C++14
0 / 100
344 ms 21752 KB
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int main(){
    int N, M, s, d, a, b;
    scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b);
    vector<int> adjList[N+1];
    for(int i=0;i<M;i++){
        int u, v;
        scanf("%d%d", &u, &v);
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }
    queue<int> proc;
    proc.push(s);
    int dists[N+1];
    for(int i=1;i<N+1;i++){
        dists[i]=-1;
    }
    dists[s]=0;
    while(!proc.empty()){
        int node=proc.front();
        proc.pop();
        for(int i=0;i<adjList[node].size();i++){
            if(dists[adjList[node][i]]==-1){
                dists[adjList[node][i]]=dists[node]+1;
                proc.push(adjList[node][i]);
            }
        }
    }
    proc.push(d);
    int distd[N+1];
    for(int i=1;i<N+1;i++){
        distd[i]=-1;
    }
    distd[d]=0;
    while(!proc.empty()){
        int node=proc.front();
        proc.pop();
        for(int i=0;i<adjList[node].size();i++){
            if(distd[adjList[node][i]]==-1){
                distd[adjList[node][i]]=distd[node]+1;
                proc.push(adjList[node][i]);
            }
        }
    }
    printf("%d", max(min(distd[a]-dists[a], distd[b]-dists[b]), -1));
    return 0;
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<adjList[node].size();i++){
                     ~^~~~~~~~~~~~~~~~~~~~~
007.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<adjList[node].size();i++){
                     ~^~~~~~~~~~~~~~~~~~~~~
007.cpp:8: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:12: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 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Incorrect 2 ms 256 KB Output isn't correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Incorrect 2 ms 256 KB Output isn't correct
13 Correct 2 ms 384 KB Output is correct
14 Incorrect 2 ms 256 KB Output isn't correct
15 Correct 24 ms 256 KB Output is correct
16 Incorrect 3 ms 384 KB Output isn't correct
17 Incorrect 3 ms 384 KB Output isn't correct
18 Incorrect 2 ms 384 KB Output isn't correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Incorrect 2 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3320 KB Output is correct
2 Incorrect 35 ms 4700 KB Output isn't correct
3 Correct 29 ms 3448 KB Output is correct
4 Incorrect 43 ms 4856 KB Output isn't correct
5 Correct 27 ms 3192 KB Output is correct
6 Correct 32 ms 3704 KB Output is correct
7 Correct 50 ms 3876 KB Output is correct
8 Correct 32 ms 3832 KB Output is correct
9 Incorrect 51 ms 4856 KB Output isn't correct
10 Correct 201 ms 13560 KB Output is correct
11 Incorrect 70 ms 6976 KB Output isn't correct
12 Correct 118 ms 8796 KB Output is correct
13 Incorrect 123 ms 7544 KB Output isn't correct
14 Correct 69 ms 6392 KB Output is correct
15 Correct 90 ms 9080 KB Output is correct
16 Correct 72 ms 9336 KB Output is correct
17 Correct 76 ms 8380 KB Output is correct
18 Incorrect 79 ms 8444 KB Output isn't correct
19 Correct 168 ms 10880 KB Output is correct
20 Incorrect 244 ms 16824 KB Output isn't correct
21 Incorrect 148 ms 12288 KB Output isn't correct
22 Correct 98 ms 10616 KB Output is correct
23 Correct 145 ms 12340 KB Output is correct
24 Correct 111 ms 12024 KB Output is correct
25 Incorrect 127 ms 11408 KB Output isn't correct
26 Correct 92 ms 10872 KB Output is correct
27 Correct 126 ms 12280 KB Output is correct
28 Correct 119 ms 12280 KB Output is correct
29 Correct 164 ms 13688 KB Output is correct
30 Incorrect 231 ms 18184 KB Output isn't correct
31 Incorrect 155 ms 14240 KB Output isn't correct
32 Correct 157 ms 12152 KB Output is correct
33 Correct 149 ms 12636 KB Output is correct
34 Incorrect 157 ms 13236 KB Output isn't correct
35 Incorrect 144 ms 12756 KB Output isn't correct
36 Incorrect 179 ms 13124 KB Output isn't correct
37 Correct 173 ms 14976 KB Output is correct
38 Correct 151 ms 14688 KB Output is correct
39 Correct 154 ms 14584 KB Output is correct
40 Incorrect 325 ms 18132 KB Output isn't correct
41 Correct 344 ms 21752 KB Output is correct