답안 #556518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556518 2022-05-03T09:36:00 Z alextodoran 007 (CEOI14_007) C++17
0 / 100
1000 ms 23572 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200000;

int N, M;

int me, him, sv1, sv2;

vector <int> adj[N_MAX + 2];

void bfs (int start, int dist[]) {
    fill(dist + 1, dist + N + 1, INT_MAX);
    queue <int> q;
    dist[start] = 0;
    q.push(start);
    while (q.empty() == false) {
        int u = q.front(); q.pop();
        for (int v : adj[u]) {
            if (dist[v] == INT_MAX) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
}

int dist1[N_MAX + 2];
int dist2[N_MAX + 2];

int dfs (int u) {
    int ret = 0;
    for (int v : adj[u]) {
        if (dist1[u] > dist1[v] && dist2[u] > dist2[v]) {
            ret = max(ret, dfs(v) + 1);
        }
    }
    return ret;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M;
    cin >> me >> him >> sv1 >> sv2;
    for (int i = 1; i <= M; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    bfs(sv1, dist1);
    bfs(sv2, dist2);

    int wait1 = dist1[him] - dist1[me];
    int wait2 = dist2[him] - dist2[me];
    int wait;
    if (wait1 != wait2) {
        wait = min(wait1, wait2);
    } else {
        int decme = dfs(me);
        int dechim = dfs(him);
        if (wait1 + decme >= dechim) {
            wait = wait1;
        } else {
            wait = wait1 + 1;
        }
    }
    cout << (wait >= 0 ? wait : -1) << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 4 ms 4948 KB Output isn't correct
5 Incorrect 4 ms 5024 KB Output isn't correct
6 Correct 3 ms 5024 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 3 ms 4948 KB Output isn't correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5024 KB Output is correct
12 Incorrect 2 ms 4948 KB Output isn't correct
13 Correct 3 ms 4948 KB Output is correct
14 Incorrect 3 ms 4984 KB Output isn't correct
15 Correct 3 ms 4948 KB Output is correct
16 Incorrect 3 ms 4948 KB Output isn't correct
17 Incorrect 3 ms 4948 KB Output isn't correct
18 Incorrect 3 ms 4948 KB Output isn't correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 5032 KB Output is correct
24 Incorrect 5 ms 5084 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 7168 KB Output is correct
2 Incorrect 34 ms 8208 KB Output isn't correct
3 Correct 22 ms 7196 KB Output is correct
4 Incorrect 27 ms 8340 KB Output isn't correct
5 Correct 19 ms 6924 KB Output is correct
6 Correct 18 ms 7216 KB Output is correct
7 Correct 21 ms 7468 KB Output is correct
8 Correct 20 ms 7500 KB Output is correct
9 Execution timed out 1075 ms 8252 KB Time limit exceeded
10 Execution timed out 1073 ms 16844 KB Time limit exceeded
11 Incorrect 44 ms 9664 KB Output isn't correct
12 Correct 56 ms 11040 KB Output is correct
13 Incorrect 52 ms 9908 KB Output isn't correct
14 Correct 37 ms 9288 KB Output is correct
15 Correct 50 ms 10956 KB Output is correct
16 Correct 57 ms 11236 KB Output is correct
17 Correct 58 ms 10540 KB Output is correct
18 Incorrect 62 ms 10524 KB Output isn't correct
19 Execution timed out 1072 ms 12920 KB Time limit exceeded
20 Execution timed out 1072 ms 18764 KB Time limit exceeded
21 Incorrect 85 ms 14028 KB Output isn't correct
22 Correct 77 ms 12100 KB Output is correct
23 Correct 99 ms 14340 KB Output is correct
24 Correct 80 ms 13460 KB Output is correct
25 Incorrect 66 ms 12676 KB Output isn't correct
26 Correct 61 ms 12444 KB Output is correct
27 Correct 75 ms 13172 KB Output is correct
28 Correct 106 ms 13192 KB Output is correct
29 Execution timed out 1080 ms 15264 KB Time limit exceeded
30 Execution timed out 1078 ms 19788 KB Time limit exceeded
31 Incorrect 89 ms 15440 KB Output isn't correct
32 Correct 76 ms 13224 KB Output is correct
33 Correct 100 ms 13728 KB Output is correct
34 Incorrect 108 ms 13956 KB Output isn't correct
35 Incorrect 116 ms 14404 KB Output isn't correct
36 Incorrect 102 ms 14772 KB Output isn't correct
37 Correct 100 ms 15180 KB Output is correct
38 Correct 93 ms 14868 KB Output is correct
39 Correct 103 ms 14836 KB Output is correct
40 Execution timed out 1057 ms 18568 KB Time limit exceeded
41 Execution timed out 1079 ms 23572 KB Time limit exceeded