답안 #240208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240208 2020-06-18T18:47:47 Z karma 007 (CEOI14_007) C++14
100 / 100
323 ms 24312 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = int(2e5) + 7;
const int logN = 18;
typedef pair<int, int> pii;

int n, m, s, d, a, b, diff1, diff2;
vector<int> adj[N], dis[2];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m >> s >> d >> a >> b;
    for(int u, v, i = 1; i <= m; ++i) {
        cin >> u >> v;
        adj[u].pb(v), adj[v].pb(u);
    }
    function<void(int, vector<int>&)> bfs = [&](int s, vector<int>& d) {
        queue<int> q; d.resize(n + 1, 1e9);
        d[s] = 0;
        for(q.push(s); q.size(); q.pop()) {
            s = q.front();
            for(int v: adj[s]) {
                if(d[v] > d[s] + 1)
                    d[v] = d[s] + 1, q.push(v);
            }
        }
    };
    bfs(a, dis[0]), bfs(b, dis[1]);
    diff1 = dis[0][d] - dis[0][s];
    diff2 = dis[1][d] - dis[1][s];
    if(diff1 != diff2) cout << max(-1, min(diff1, diff2));
    else {
        function<int(int)> bfs = [&](int s) {
            vector<int> d; d.resize(n + 1, 1e9);
            queue<int> q; d[s] = 0;
            for(q.push(s); q.size(); q.pop()) {
                s = q.front();
                for(int v: adj[s]) {
                    if(dis[0][v] == dis[0][s] - 1 && dis[0][v] == dis[1][v] && d[v] == 1e9)
                        q.push(v), d[v] = d[s] + 1;
                }
            }
            return d[s];
        };
        cout << max(-1, diff1 - (diff1 + bfs(s) < bfs(d)));
    }
}

Compilation message

007.cpp: In function 'int32_t main()':
007.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 8 ms 4992 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 4992 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 7 ms 4992 KB Output is correct
12 Correct 8 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 8 ms 5120 KB Output is correct
19 Correct 8 ms 5120 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Correct 8 ms 5120 KB Output is correct
22 Correct 8 ms 5120 KB Output is correct
23 Correct 9 ms 5120 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 7288 KB Output is correct
2 Correct 36 ms 8336 KB Output is correct
3 Correct 29 ms 7504 KB Output is correct
4 Correct 36 ms 8452 KB Output is correct
5 Correct 27 ms 7168 KB Output is correct
6 Correct 27 ms 7296 KB Output is correct
7 Correct 34 ms 7736 KB Output is correct
8 Correct 31 ms 7740 KB Output is correct
9 Correct 44 ms 8628 KB Output is correct
10 Correct 163 ms 17400 KB Output is correct
11 Correct 57 ms 10004 KB Output is correct
12 Correct 82 ms 11512 KB Output is correct
13 Correct 63 ms 10488 KB Output is correct
14 Correct 51 ms 9592 KB Output is correct
15 Correct 77 ms 11568 KB Output is correct
16 Correct 82 ms 11384 KB Output is correct
17 Correct 72 ms 11084 KB Output is correct
18 Correct 71 ms 11084 KB Output is correct
19 Correct 114 ms 13536 KB Output is correct
20 Correct 213 ms 19320 KB Output is correct
21 Correct 106 ms 13952 KB Output is correct
22 Correct 96 ms 12792 KB Output is correct
23 Correct 109 ms 13964 KB Output is correct
24 Correct 100 ms 13712 KB Output is correct
25 Correct 103 ms 13332 KB Output is correct
26 Correct 104 ms 12920 KB Output is correct
27 Correct 129 ms 13956 KB Output is correct
28 Correct 110 ms 13960 KB Output is correct
29 Correct 151 ms 15828 KB Output is correct
30 Correct 221 ms 20344 KB Output is correct
31 Correct 123 ms 15400 KB Output is correct
32 Correct 115 ms 13944 KB Output is correct
33 Correct 116 ms 14200 KB Output is correct
34 Correct 129 ms 14728 KB Output is correct
35 Correct 107 ms 14200 KB Output is correct
36 Correct 116 ms 14588 KB Output is correct
37 Correct 148 ms 15224 KB Output is correct
38 Correct 172 ms 15760 KB Output is correct
39 Correct 141 ms 15632 KB Output is correct
40 Correct 226 ms 19380 KB Output is correct
41 Correct 323 ms 24312 KB Output is correct