Submission #78653

# Submission time Handle Problem Language Result Execution time Memory
78653 2018-10-06T20:41:33 Z duality 007 (CEOI14_007) C++11
0 / 100
396 ms 21372 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

vi adjList[200000];
int dist1[200000],dist2[200000];
int visited[200000],m;
int doDFS(int u) {
    if (visited[u]) return 0;
    int i;
    visited[u] = 1;
    m = min(m,dist1[u]);
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (dist1[v] == dist2[v]) doDFS(v);
    }
    return 0;
}
queue<int> Q;
int main() {
    int i;
    int N,M;
    int s,d,a,b,u,v;
    scanf("%d %d",&N,&M);
    scanf("%d %d %d %d",&s,&d,&a,&b);
    s--,d--,a--,b--;
    for (i = 0; i < M; i++) {
        scanf("%d %d",&u,&v);
        u--,v--;
        adjList[u].pb(v);
        adjList[v].pb(u);
    }

    fill(dist1,dist1+N,-1);
    dist1[a] = 0;
    Q.push(a);
    while (!Q.empty()) {
        u = Q.front();
        Q.pop();

        for (i = 0; i < adjList[u].size(); i++) {
            v = adjList[u][i];
            if (dist1[v] == -1) {
                dist1[v] = dist1[u]+1;
                Q.push(v);
            }
        }
    }
    fill(dist2,dist2+N,-1);
    dist2[b] = 0;
    Q.push(b);
    while (!Q.empty()) {
        u = Q.front();
        Q.pop();

        for (i = 0; i < adjList[u].size(); i++) {
            v = adjList[u][i];
            if (dist2[v] == -1) {
                dist2[v] = dist2[u]+1;
                Q.push(v);
            }
        }
    }
    int ans = max(min(dist1[d]-dist1[s],dist2[d]-dist2[s]),-1);
    if (dist1[s] != dist2[s]) {
        if (dist1[s] < dist2[s]) {
            if (dist2[d] == ans+dist1[s]) ans--;
        }
        else {
            if (dist1[d] == ans+dist2[s]) ans--;
        }
        printf("%d\n",max(ans,-1));
    }
    else {
        if (dist1[d] != dist2[d]) printf("%d\n",ans);
        else {
            m = N,doDFS(s);
            int t = m;
            if (!visited[d]) {
                m = N,doDFS(d);
                if (m < t) ans--;
            }
            printf("%d\n",max(ans,-1));
        }
    }

    return 0;
}

Compilation message

007.cpp: In function 'int doDFS(int)':
007.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
007.cpp: In function 'int main()':
007.cpp:94:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
007.cpp:109:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
007.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~
007.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d",&s,&d,&a,&b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 7 ms 5244 KB Output is correct
3 Correct 6 ms 5244 KB Output is correct
4 Correct 6 ms 5244 KB Output is correct
5 Incorrect 6 ms 5244 KB Output isn't correct
6 Correct 6 ms 5244 KB Output is correct
7 Correct 6 ms 5244 KB Output is correct
8 Correct 6 ms 5260 KB Output is correct
9 Correct 6 ms 5260 KB Output is correct
10 Correct 7 ms 5316 KB Output is correct
11 Correct 7 ms 5356 KB Output is correct
12 Incorrect 6 ms 5384 KB Output isn't correct
13 Correct 6 ms 5384 KB Output is correct
14 Incorrect 6 ms 5384 KB Output isn't correct
15 Correct 6 ms 5384 KB Output is correct
16 Incorrect 6 ms 5384 KB Output isn't correct
17 Correct 6 ms 5384 KB Output is correct
18 Correct 7 ms 5384 KB Output is correct
19 Correct 6 ms 5384 KB Output is correct
20 Correct 6 ms 5384 KB Output is correct
21 Correct 6 ms 5384 KB Output is correct
22 Correct 6 ms 5384 KB Output is correct
23 Correct 6 ms 5384 KB Output is correct
24 Incorrect 8 ms 5384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 7084 KB Output is correct
2 Correct 36 ms 8188 KB Output is correct
3 Correct 32 ms 8188 KB Output is correct
4 Correct 40 ms 8188 KB Output is correct
5 Correct 29 ms 8188 KB Output is correct
6 Correct 28 ms 8188 KB Output is correct
7 Correct 34 ms 8188 KB Output is correct
8 Correct 33 ms 8188 KB Output is correct
9 Incorrect 57 ms 8992 KB Output isn't correct
10 Correct 204 ms 13612 KB Output is correct
11 Incorrect 66 ms 13612 KB Output isn't correct
12 Correct 81 ms 13612 KB Output is correct
13 Correct 65 ms 13612 KB Output is correct
14 Correct 52 ms 13612 KB Output is correct
15 Correct 84 ms 13612 KB Output is correct
16 Correct 84 ms 13612 KB Output is correct
17 Correct 76 ms 13612 KB Output is correct
18 Correct 75 ms 13612 KB Output is correct
19 Correct 146 ms 13692 KB Output is correct
20 Incorrect 280 ms 16764 KB Output isn't correct
21 Correct 115 ms 16764 KB Output is correct
22 Correct 109 ms 16764 KB Output is correct
23 Correct 111 ms 16764 KB Output is correct
24 Correct 152 ms 16764 KB Output is correct
25 Incorrect 119 ms 16764 KB Output isn't correct
26 Correct 106 ms 16764 KB Output is correct
27 Correct 117 ms 16764 KB Output is correct
28 Correct 129 ms 16764 KB Output is correct
29 Correct 203 ms 16764 KB Output is correct
30 Incorrect 346 ms 17836 KB Output isn't correct
31 Correct 138 ms 17836 KB Output is correct
32 Correct 125 ms 17836 KB Output is correct
33 Correct 115 ms 17836 KB Output is correct
34 Incorrect 187 ms 17836 KB Output isn't correct
35 Correct 148 ms 17836 KB Output is correct
36 Correct 208 ms 17836 KB Output is correct
37 Correct 155 ms 17836 KB Output is correct
38 Correct 138 ms 17836 KB Output is correct
39 Correct 161 ms 17836 KB Output is correct
40 Correct 281 ms 19196 KB Output is correct
41 Correct 396 ms 21372 KB Output is correct