답안 #90721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90721 2018-12-24T01:51:24 Z combi2k2 007 (CEOI14_007) C++14
100 / 100
307 ms 17372 KB
#include<bits/stdc++.h>

using namespace std;

const int   N   = 2e5 + 1;

vector<int> g[N];

int fa[N];
int fb[N];
int n;

int bfs(int s,int d[])  {
    fill(d + 1,d + 1 + n,-1);

    d[s] = 0;
    queue<int>  q;
    q.push(s);

    while(q.size()) {
        int u = q.front();  q.pop();
        for(int v : g[u])
            if (d[v] < 0)   {
                d[v] = d[u] + 1;
                q.push(v);
            }
    }

    return  1;
}
int go(int s)   {
    vector<int> d(n + 1,-1);
    d[s] = -1;
    queue<int>  q;
    q.push(s);
    int ans = 0;
    while(q.size()) {
        int u = q.front();  q.pop();
        for(int v : g[u])
            if (fa[v] + 1 == fa[u] && fb[v] + 1 == fb[u] && d[v] < 0)   {
                d[v] = d[u] + 1;
                ans = max(ans,d[v]);
                q.push(v);
            }
    }
    return  ans;
}

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

    int m, s, d, a, b;

    cin >> n >> m >> s >> d >> a >> b;

    while (m--) {
        int x, y;   cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    bfs(a,fa);
    bfs(b,fb);

    int dA = fa[d] - fa[s];
    int dB = fb[d] - fb[s];

    if (dA != dB)   cout << max(min(dA,dB),-1);
    if (dA == dB)   cout << max(dA - (dA + go(s) < go(d)),-1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5112 KB Output is correct
2 Correct 5 ms 5232 KB Output is correct
3 Correct 5 ms 5232 KB Output is correct
4 Correct 5 ms 5232 KB Output is correct
5 Correct 5 ms 5232 KB Output is correct
6 Correct 5 ms 5240 KB Output is correct
7 Correct 5 ms 5240 KB Output is correct
8 Correct 6 ms 5368 KB Output is correct
9 Correct 5 ms 5368 KB Output is correct
10 Correct 5 ms 5368 KB Output is correct
11 Correct 5 ms 5368 KB Output is correct
12 Correct 6 ms 5440 KB Output is correct
13 Correct 5 ms 5440 KB Output is correct
14 Correct 5 ms 5440 KB Output is correct
15 Correct 5 ms 5440 KB Output is correct
16 Correct 6 ms 5440 KB Output is correct
17 Correct 6 ms 5440 KB Output is correct
18 Correct 6 ms 5440 KB Output is correct
19 Correct 6 ms 5440 KB Output is correct
20 Correct 6 ms 5440 KB Output is correct
21 Correct 6 ms 5440 KB Output is correct
22 Correct 6 ms 5440 KB Output is correct
23 Correct 6 ms 5440 KB Output is correct
24 Correct 6 ms 5508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 7116 KB Output is correct
2 Correct 33 ms 7896 KB Output is correct
3 Correct 25 ms 7896 KB Output is correct
4 Correct 35 ms 8028 KB Output is correct
5 Correct 26 ms 8028 KB Output is correct
6 Correct 26 ms 8028 KB Output is correct
7 Correct 29 ms 8028 KB Output is correct
8 Correct 30 ms 8028 KB Output is correct
9 Correct 39 ms 8028 KB Output is correct
10 Correct 150 ms 12280 KB Output is correct
11 Correct 52 ms 12280 KB Output is correct
12 Correct 59 ms 12280 KB Output is correct
13 Correct 49 ms 12280 KB Output is correct
14 Correct 37 ms 12280 KB Output is correct
15 Correct 57 ms 12280 KB Output is correct
16 Correct 63 ms 12280 KB Output is correct
17 Correct 53 ms 12280 KB Output is correct
18 Correct 56 ms 12280 KB Output is correct
19 Correct 104 ms 12280 KB Output is correct
20 Correct 181 ms 14224 KB Output is correct
21 Correct 102 ms 14224 KB Output is correct
22 Correct 86 ms 14224 KB Output is correct
23 Correct 104 ms 14224 KB Output is correct
24 Correct 114 ms 14224 KB Output is correct
25 Correct 103 ms 14224 KB Output is correct
26 Correct 107 ms 14224 KB Output is correct
27 Correct 114 ms 14224 KB Output is correct
28 Correct 123 ms 14224 KB Output is correct
29 Correct 171 ms 14224 KB Output is correct
30 Correct 254 ms 14812 KB Output is correct
31 Correct 129 ms 14812 KB Output is correct
32 Correct 137 ms 14812 KB Output is correct
33 Correct 125 ms 14812 KB Output is correct
34 Correct 139 ms 14812 KB Output is correct
35 Correct 110 ms 14812 KB Output is correct
36 Correct 94 ms 14812 KB Output is correct
37 Correct 111 ms 14812 KB Output is correct
38 Correct 105 ms 14812 KB Output is correct
39 Correct 141 ms 14812 KB Output is correct
40 Correct 202 ms 15200 KB Output is correct
41 Correct 307 ms 17372 KB Output is correct