답안 #153476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153476 2019-09-14T09:09:08 Z Mercenary 007 (CEOI14_007) C++14
0 / 100
248 ms 18808 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 250000 + 5;
int n , m , s , d , a , b;
vector<int> adj[maxn];
int ds[maxn] , dd[maxn] , da[maxn] , db[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m >> s >> d >> a >> b;
    for(int i = 1 ; i <= n ; ++i){
        int u , v;cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    auto BFS = [&](int u , int d[maxn]){
        queue<int> q;
        fill_n(d,maxn,-1);
        d[u] = 0;
        q.push(u);
        while(q.size()){
            int u = q.front();q.pop();
            for(int c : adj[u]){
                if(d[c] == -1){
                    d[c] = d[u] + 1;
                    q.push(c);
                }
            }
        }
    };
    BFS(s , ds);BFS(d , dd);BFS(a , da);BFS(b , db);
    if(dd[a] + 1 <= ds[a] || dd[b] + 1 <= ds[b]){
        return cout << -1 , 0;
    }
    int res = 0;
    if(dd[a] - ds[a] == dd[b] - ds[b]){
        int sres = 0  , dres = 0;
        for(int i = 1 ; i <= n ; ++i){
            if(ds[a] == da[i] + ds[i] && ds[b] == db[i] + ds[i]){
                sres = max(sres , ds[i]);
            }
            if(dd[a] == da[i] + dd[i] && dd[b] == db[i] + dd[i]){
                dres = max(dres , dd[i]);
            }
        }
//        cout << sres << " " << dres << endl;
        cout << dd[a] - ds[a] - (sres + dd[a] - ds[a] < dres);
    }else{
        cout << min(dd[a] - ds[a] , dd[b] - ds[b]);
    }
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:54:9: warning: unused variable 'res' [-Wunused-variable]
     int res = 0;
         ^~~
007.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10104 KB Output is correct
2 Correct 11 ms 10104 KB Output is correct
3 Correct 11 ms 10104 KB Output is correct
4 Correct 10 ms 10104 KB Output is correct
5 Correct 11 ms 10104 KB Output is correct
6 Incorrect 10 ms 10104 KB Output isn't correct
7 Incorrect 10 ms 10104 KB Output isn't correct
8 Correct 11 ms 10104 KB Output is correct
9 Correct 11 ms 10104 KB Output is correct
10 Correct 11 ms 10104 KB Output is correct
11 Correct 11 ms 10104 KB Output is correct
12 Correct 11 ms 10104 KB Output is correct
13 Correct 11 ms 10104 KB Output is correct
14 Incorrect 10 ms 10104 KB Output isn't correct
15 Incorrect 11 ms 10104 KB Output isn't correct
16 Incorrect 11 ms 10104 KB Output isn't correct
17 Correct 11 ms 10104 KB Output is correct
18 Correct 11 ms 10104 KB Output is correct
19 Correct 11 ms 10108 KB Output is correct
20 Correct 11 ms 10232 KB Output is correct
21 Correct 11 ms 10104 KB Output is correct
22 Incorrect 11 ms 10104 KB Output isn't correct
23 Correct 11 ms 10100 KB Output is correct
24 Correct 11 ms 10084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 11772 KB Output is correct
2 Correct 57 ms 12620 KB Output is correct
3 Correct 39 ms 11896 KB Output is correct
4 Correct 55 ms 12800 KB Output is correct
5 Correct 36 ms 11768 KB Output is correct
6 Correct 43 ms 12028 KB Output is correct
7 Incorrect 42 ms 12284 KB Output isn't correct
8 Incorrect 44 ms 12152 KB Output isn't correct
9 Incorrect 33 ms 12408 KB Output isn't correct
10 Incorrect 39 ms 12920 KB Output isn't correct
11 Correct 81 ms 13952 KB Output is correct
12 Correct 106 ms 14768 KB Output is correct
13 Correct 86 ms 14200 KB Output is correct
14 Correct 76 ms 13632 KB Output is correct
15 Correct 105 ms 15096 KB Output is correct
16 Correct 130 ms 15412 KB Output is correct
17 Incorrect 110 ms 14840 KB Output isn't correct
18 Incorrect 113 ms 14840 KB Output isn't correct
19 Incorrect 63 ms 15096 KB Output isn't correct
20 Incorrect 65 ms 15304 KB Output isn't correct
21 Correct 181 ms 17068 KB Output is correct
22 Correct 154 ms 16124 KB Output is correct
23 Correct 164 ms 17016 KB Output is correct
24 Correct 180 ms 17032 KB Output is correct
25 Correct 166 ms 16504 KB Output is correct
26 Correct 154 ms 16284 KB Output is correct
27 Incorrect 161 ms 17144 KB Output isn't correct
28 Incorrect 186 ms 17016 KB Output isn't correct
29 Incorrect 91 ms 16516 KB Output isn't correct
30 Incorrect 96 ms 15992 KB Output isn't correct
31 Correct 209 ms 18168 KB Output is correct
32 Correct 182 ms 16876 KB Output is correct
33 Correct 200 ms 17400 KB Output is correct
34 Correct 212 ms 17784 KB Output is correct
35 Correct 185 ms 17336 KB Output is correct
36 Correct 205 ms 17656 KB Output is correct
37 Correct 226 ms 18808 KB Output is correct
38 Incorrect 225 ms 18508 KB Output isn't correct
39 Correct 248 ms 18424 KB Output is correct
40 Incorrect 107 ms 18180 KB Output isn't correct
41 Incorrect 103 ms 18016 KB Output isn't correct