Submission #101466

# Submission time Handle Problem Language Result Execution time Memory
101466 2019-03-19T02:46:46 Z dwsc 007 (CEOI14_007) C++14
0 / 100
769 ms 50456 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> adj[m];
    int s,d,a,b;
    cin >> s >> d >> a >> b;
    s--;
    d--;
    a--;
    b--;
    for (int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    queue<int> q;
    int dist1[n],dist2[n];
    memset(dist1,-1,sizeof(dist1));
    memset(dist2,-1,sizeof(dist2));
    dist1[s] = 0;
    dist2[d] = 0;
    q.push(s);
    while (!q.empty()){
        int u = q.front();
        q.pop();
        for (int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i];
            if (dist1[v] == -1){
                dist1[v] = dist1[u]+1;
                q.push(v);
            }
        }
    }
    q.push(d);
    while (!q.empty()){
        int u = q.front();
        q.pop();
        for (int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i];
            if (dist2[v] == -1){
                dist2[v] = dist2[u]+1;
                q.push(v);
            }
        }
    }
   // cout << dist1[a] << " " << dist1[b] << "\n";
   // cout << dist2[a] << " " << dist2[b] << "\n";
    if (dist2[a] < dist1[a] && dist2[b] < dist1[b]) cout << -1;
    else{
        if (dist1[a] > dist1[b]){
            swap(dist1[a],dist1[b]);
            swap(dist2[a],dist2[b]);
        }
        if (dist1[a] == dist1[b]){
            if (dist2[a] == dist2[b]) cout << 1/0;
            else if (dist2[a]+1 == dist2[b]) cout << dist2[a] - dist1[a];
            else cout << dist2[b] - dist1[b];
        }
        else if (dist1[a]+1 == dist1[b]){
            if (dist2[a] == dist2[b]) cout << dist2[b] - dist1[b];
            else if (dist2[a] +1 == dist2[b]) cout << dist2[a] - dist1[a];
            else cout << dist2[b] - dist1[b];
        }
    }
}/*
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:31:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < adj[u].size(); i++){
                         ~~^~~~~~~~~~~~~~~
007.cpp:43:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < adj[u].size(); i++){
                         ~~^~~~~~~~~~~~~~~
007.cpp:60:48: warning: division by zero [-Wdiv-by-zero]
             if (dist2[a] == dist2[b]) cout << 1/0;
                                               ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Runtime error 2 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
4 Runtime error 3 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
5 Runtime error 3 ms 384 KB Execution killed with signal 8 (could be triggered by violating memory limits)
6 Runtime error 2 ms 384 KB Execution killed with signal 8 (could be triggered by violating memory limits)
7 Runtime error 3 ms 384 KB Execution killed with signal 8 (could be triggered by violating memory limits)
8 Runtime error 2 ms 384 KB Execution killed with signal 8 (could be triggered by violating memory limits)
9 Runtime error 3 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
10 Correct 3 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Runtime error 3 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
13 Runtime error 2 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
14 Runtime error 3 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
15 Runtime error 2 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
16 Runtime error 3 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
17 Runtime error 4 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
18 Runtime error 4 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
19 Runtime error 4 ms 640 KB Execution killed with signal 8 (could be triggered by violating memory limits)
20 Runtime error 3 ms 640 KB Execution killed with signal 8 (could be triggered by violating memory limits)
21 Correct 2 ms 384 KB Output is correct
22 Runtime error 3 ms 640 KB Execution killed with signal 8 (could be triggered by violating memory limits)
23 Runtime error 4 ms 640 KB Execution killed with signal 8 (could be triggered by violating memory limits)
24 Runtime error 4 ms 640 KB Execution killed with signal 8 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 5784 KB Execution killed with signal 8 (could be triggered by violating memory limits)
2 Runtime error 72 ms 7912 KB Execution killed with signal 8 (could be triggered by violating memory limits)
3 Runtime error 44 ms 6008 KB Execution killed with signal 8 (could be triggered by violating memory limits)
4 Runtime error 65 ms 8156 KB Execution killed with signal 8 (could be triggered by violating memory limits)
5 Correct 45 ms 2936 KB Output is correct
6 Correct 50 ms 3192 KB Output is correct
7 Runtime error 52 ms 6520 KB Execution killed with signal 8 (could be triggered by violating memory limits)
8 Runtime error 55 ms 6648 KB Execution killed with signal 8 (could be triggered by violating memory limits)
9 Runtime error 83 ms 9464 KB Execution killed with signal 8 (could be triggered by violating memory limits)
10 Runtime error 441 ms 35356 KB Execution killed with signal 8 (could be triggered by violating memory limits)
11 Runtime error 120 ms 11896 KB Execution killed with signal 8 (could be triggered by violating memory limits)
12 Runtime error 233 ms 15224 KB Execution killed with signal 8 (could be triggered by violating memory limits)
13 Runtime error 133 ms 13064 KB Execution killed with signal 8 (could be triggered by violating memory limits)
14 Correct 93 ms 5496 KB Output is correct
15 Runtime error 187 ms 14968 KB Execution killed with signal 8 (could be triggered by violating memory limits)
16 Correct 152 ms 8056 KB Output is correct
17 Runtime error 137 ms 14200 KB Execution killed with signal 8 (could be triggered by violating memory limits)
18 Runtime error 134 ms 14160 KB Execution killed with signal 8 (could be triggered by violating memory limits)
19 Runtime error 237 ms 21516 KB Execution killed with signal 8 (could be triggered by violating memory limits)
20 Runtime error 484 ms 39160 KB Execution killed with signal 8 (could be triggered by violating memory limits)
21 Runtime error 217 ms 20604 KB Execution killed with signal 8 (could be triggered by violating memory limits)
22 Runtime error 161 ms 17912 KB Execution killed with signal 8 (could be triggered by violating memory limits)
23 Correct 275 ms 10232 KB Output is correct
24 Runtime error 196 ms 20216 KB Execution killed with signal 8 (could be triggered by violating memory limits)
25 Runtime error 194 ms 19064 KB Execution killed with signal 8 (could be triggered by violating memory limits)
26 Correct 169 ms 9204 KB Output is correct
27 Runtime error 230 ms 20492 KB Execution killed with signal 8 (could be triggered by violating memory limits)
28 Runtime error 201 ms 20728 KB Execution killed with signal 8 (could be triggered by violating memory limits)
29 Runtime error 305 ms 27128 KB Execution killed with signal 8 (could be triggered by violating memory limits)
30 Runtime error 548 ms 41316 KB Execution killed with signal 8 (could be triggered by violating memory limits)
31 Runtime error 257 ms 23676 KB Execution killed with signal 8 (could be triggered by violating memory limits)
32 Runtime error 281 ms 20476 KB Execution killed with signal 8 (could be triggered by violating memory limits)
33 Correct 243 ms 10720 KB Output is correct
34 Runtime error 253 ms 22172 KB Execution killed with signal 8 (could be triggered by violating memory limits)
35 Runtime error 200 ms 21112 KB Execution killed with signal 8 (could be triggered by violating memory limits)
36 Runtime error 231 ms 22116 KB Execution killed with signal 8 (could be triggered by violating memory limits)
37 Correct 301 ms 12704 KB Output is correct
38 Runtime error 237 ms 24184 KB Execution killed with signal 8 (could be triggered by violating memory limits)
39 Runtime error 283 ms 24508 KB Execution killed with signal 8 (could be triggered by violating memory limits)
40 Runtime error 377 ms 35436 KB Execution killed with signal 8 (could be triggered by violating memory limits)
41 Runtime error 769 ms 50456 KB Execution killed with signal 8 (could be triggered by violating memory limits)