답안 #118456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118456 2019-06-19T03:59:37 Z minhtung0404 007 (CEOI14_007) C++17
53.3333 / 100
154 ms 15124 KB
//https://oj.uz/problem/view/CEOI14_007

#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;

vector <int> G[N];
int n, m, p[2], a[2];
int d[2][N], d2[N], Max[N];
bool ck[N];

void bfs(int u, int t){
    queue <int> mq; mq.push(u); d[t][u] = 1;
    while (mq.size()){
        u = mq.front(); mq.pop();
        for (auto v : G[u]){
            if (!d[t][v]){
                d[t][v] = d[t][u] + 1;
                mq.push(v);
            }
        }
    }
}

void dfs(int u){
    Max[u] = 1;
    for (auto v : G[u]){
        if (d[0][v] + 1 == d[0][u] && d[1][v] + 1 == d[1][u]){
            if (!Max[v]) dfs(v);
            Max[u] = max(Max[u], Max[v] + 1);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    cin >> p[0] >> p[1] >> a[0] >> a[1];
    while (m--){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    bfs(a[0], 0); bfs(a[1], 1);
    for (int i = 1; i <= n; i++){
        if (d[0][i] < d[0][p[0]] || d[1][i] < d[1][p[0]]) ck[i] = true;
    }
    if (d[0][p[0]] == d[1][p[0]]){
        for (int i = 1; i <= n; i++){
            if (d[0][i] == d[1][i] && d[0][i] == d[0][p[0]] && !Max[i]) dfs(i);
        }
        for (int i = 1; i <= n; i++) if (Max[i] > Max[p[0]]) ck[i] = true;
    }
    queue <int> mq; mq.push(p[1]); d2[p[1]] = 1;
    while (mq.size()){
        int u = mq.front(); mq.pop();
        if (ck[u]) return cout << d2[u] - 2, 0;
        for (auto v : G[u]){
            if (!d2[v]){
                d2[v] = d2[u] + 1;
                mq.push(v);
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2816 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2816 KB Output is correct
20 Correct 4 ms 2816 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2816 KB Output is correct
23 Correct 4 ms 2816 KB Output is correct
24 Correct 5 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 5112 KB Output is correct
2 Correct 30 ms 6492 KB Output is correct
3 Correct 24 ms 5220 KB Output is correct
4 Correct 32 ms 6520 KB Output is correct
5 Correct 33 ms 4856 KB Output is correct
6 Correct 26 ms 5240 KB Output is correct
7 Correct 27 ms 5372 KB Output is correct
8 Correct 31 ms 5624 KB Output is correct
9 Correct 45 ms 6528 KB Output is correct
10 Correct 154 ms 15124 KB Output is correct
11 Correct 51 ms 8184 KB Output is correct
12 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Correct 58 ms 8288 KB Output is correct
14 Correct 47 ms 7416 KB Output is correct
15 Runtime error 7 ms 5220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 7 ms 5220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 6 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 6 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)