Submission #101461

# Submission time Handle Problem Language Result Execution time Memory
101461 2019-03-19T02:43:54 Z dwsc 007 (CEOI14_007) C++14
0 / 100
563 ms 25308 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 << dist2[a] - dist1[a];
            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]){
            cout << 1/0;
            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:65:22: warning: division by zero [-Wdiv-by-zero]
             cout << 1/0;
                     ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
2 Runtime error 2 ms 512 KB Execution killed with signal 8 (could be triggered by violating memory limits)
3 Correct 2 ms 128 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Incorrect 3 ms 256 KB Output isn't correct
9 Correct 3 ms 256 KB Output is correct
10 Runtime error 2 ms 384 KB Execution killed with signal 8 (could be triggered by violating memory limits)
11 Correct 2 ms 256 KB Output is correct
12 Incorrect 2 ms 384 KB Output isn't correct
13 Correct 3 ms 384 KB Output is correct
14 Incorrect 2 ms 384 KB Output isn't correct
15 Correct 2 ms 384 KB Output is correct
16 Incorrect 2 ms 384 KB Output isn't correct
17 Incorrect 2 ms 384 KB Output isn't correct
18 Incorrect 3 ms 384 KB Output isn't correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Runtime error 3 ms 640 KB Execution killed with signal 8 (could be triggered by violating memory limits)
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Incorrect 3 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 2936 KB Output is correct
2 Incorrect 59 ms 4088 KB Output isn't correct
3 Correct 45 ms 3064 KB Output is correct
4 Incorrect 63 ms 4088 KB Output isn't correct
5 Runtime error 50 ms 5624 KB Execution killed with signal 8 (could be triggered by violating memory limits)
6 Runtime error 49 ms 6136 KB Execution killed with signal 8 (could be triggered by violating memory limits)
7 Correct 46 ms 3328 KB Output is correct
8 Correct 67 ms 3448 KB Output is correct
9 Incorrect 90 ms 4856 KB Output isn't correct
10 Correct 419 ms 17744 KB Output is correct
11 Incorrect 109 ms 6136 KB Output isn't correct
12 Correct 172 ms 7692 KB Output is correct
13 Incorrect 114 ms 6520 KB Output isn't correct
14 Correct 102 ms 5584 KB Output is correct
15 Correct 152 ms 7672 KB Output is correct
16 Runtime error 146 ms 15860 KB Execution killed with signal 8 (could be triggered by violating memory limits)
17 Correct 166 ms 7160 KB Output is correct
18 Incorrect 130 ms 7220 KB Output isn't correct
19 Correct 250 ms 10964 KB Output is correct
20 Incorrect 463 ms 19664 KB Output isn't correct
21 Incorrect 187 ms 10360 KB Output isn't correct
22 Correct 164 ms 9080 KB Output is correct
23 Runtime error 198 ms 20316 KB Execution killed with signal 8 (could be triggered by violating memory limits)
24 Correct 189 ms 10204 KB Output is correct
25 Incorrect 171 ms 9592 KB Output isn't correct
26 Runtime error 177 ms 18204 KB Execution killed with signal 8 (could be triggered by violating memory limits)
27 Correct 212 ms 10460 KB Output is correct
28 Correct 202 ms 10360 KB Output is correct
29 Correct 289 ms 13560 KB Output is correct
30 Incorrect 484 ms 20728 KB Output isn't correct
31 Incorrect 258 ms 12024 KB Output isn't correct
32 Correct 266 ms 10416 KB Output is correct
33 Runtime error 198 ms 21116 KB Execution killed with signal 8 (could be triggered by violating memory limits)
34 Incorrect 242 ms 11324 KB Output isn't correct
35 Incorrect 185 ms 10744 KB Output isn't correct
36 Incorrect 208 ms 11256 KB Output isn't correct
37 Runtime error 259 ms 24944 KB Execution killed with signal 8 (could be triggered by violating memory limits)
38 Correct 259 ms 12356 KB Output is correct
39 Correct 262 ms 12336 KB Output is correct
40 Incorrect 380 ms 17828 KB Output isn't correct
41 Correct 563 ms 25308 KB Output is correct