Submission #727502

# Submission time Handle Problem Language Result Execution time Memory
727502 2023-04-20T21:34:16 Z n0sk1ll 007 (CEOI14_007) C++17
100 / 100
240 ms 18436 KB
#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;







//Note to self: Check for overflow

graph g(200005);
bool vis[200005];
int duba[200005];
int dubb[200005];

int main()
{
    FAST;

    int n,m; cin>>n>>m;
    int ona,on,a,b; cin>>ona>>on>>a>>b;
    while (m--)
    {
        int u,v; cin>>u>>v;
        g[u].pb(v),g[v].pb(u);
    }

    queue<pii> bfs;

    bfs.push({a,0});
    while (!bfs.empty())
    {
        auto [p,d]=bfs.front(); bfs.pop();
        if (vis[p]) continue; vis[p]=true,duba[p]=d;
        for (auto it : g[p]) bfs.push({it,d+1});
    }

    fff(i,1,n) vis[i]=false;
    bfs.push({b,0});
    while (!bfs.empty())
    {
        auto [p,d]=bfs.front(); bfs.pop();
        if (vis[p]) continue; vis[p]=true,dubb[p]=d;
        for (auto it : g[p]) bfs.push({it,d+1});
    }

    if (duba[on]<duba[ona]) return cout<<-1,0;
    if (dubb[on]<dubb[ona]) return cout<<-1,0;
    if (duba[on]-duba[ona]<dubb[on]-dubb[ona]) return cout<<duba[on]-duba[ona],0;
    if (duba[on]-duba[ona]>dubb[on]-dubb[ona]) return cout<<dubb[on]-dubb[ona],0;

    fff(i,1,n) vis[i]=false;
    int korakona=0;
    bfs.push({ona,0});
    while (!bfs.empty())
    {
        auto [p,d]=bfs.front(); bfs.pop();
        if (vis[p]) continue; vis[p]=true;
        if (d>korakona) korakona=d;
        for (auto it : g[p]) if (duba[it]<duba[p] && dubb[it]<dubb[p]) bfs.push({it,d+1});
    }

    fff(i,1,n) vis[i]=false;
    int korakon=0;
    bfs.push({on,0});
    while (!bfs.empty())
    {
        auto [p,d]=bfs.front(); bfs.pop();
        if (vis[p]) continue; vis[p]=true;
        if (d>korakon) korakon=d;
        for (auto it : g[p]) if (duba[it]<duba[p] && dubb[it]<dubb[p]) bfs.push({it,d+1});
    }

    if (duba[on]-duba[ona]+korakona >= korakon) return cout<<duba[on]-duba[ona],0;
    cout<<duba[on]-duba[ona]-1;
}

//Note to self: Check for overflow

Compilation message

007.cpp: In function 'int main()':
007.cpp:60:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   60 |         if (vis[p]) continue; vis[p]=true,duba[p]=d;
      |         ^~
007.cpp:60:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   60 |         if (vis[p]) continue; vis[p]=true,duba[p]=d;
      |                               ^~~
007.cpp:69:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   69 |         if (vis[p]) continue; vis[p]=true,dubb[p]=d;
      |         ^~
007.cpp:69:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   69 |         if (vis[p]) continue; vis[p]=true,dubb[p]=d;
      |                               ^~~
007.cpp:84:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   84 |         if (vis[p]) continue; vis[p]=true;
      |         ^~
007.cpp:84:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   84 |         if (vis[p]) continue; vis[p]=true;
      |                               ^~~
007.cpp:95:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   95 |         if (vis[p]) continue; vis[p]=true;
      |         ^~
007.cpp:95:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   95 |         if (vis[p]) continue; vis[p]=true;
      |                               ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5040 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 5044 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5048 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4968 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5084 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5040 KB Output is correct
24 Correct 5 ms 5052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 7104 KB Output is correct
2 Correct 23 ms 8056 KB Output is correct
3 Correct 19 ms 7252 KB Output is correct
4 Correct 23 ms 8140 KB Output is correct
5 Correct 16 ms 7072 KB Output is correct
6 Correct 19 ms 7288 KB Output is correct
7 Correct 18 ms 7496 KB Output is correct
8 Correct 21 ms 7508 KB Output is correct
9 Correct 32 ms 8416 KB Output is correct
10 Correct 138 ms 13892 KB Output is correct
11 Correct 35 ms 9708 KB Output is correct
12 Correct 55 ms 11072 KB Output is correct
13 Correct 49 ms 10108 KB Output is correct
14 Correct 31 ms 9188 KB Output is correct
15 Correct 47 ms 11084 KB Output is correct
16 Correct 50 ms 11316 KB Output is correct
17 Correct 53 ms 10636 KB Output is correct
18 Correct 47 ms 10664 KB Output is correct
19 Correct 83 ms 12540 KB Output is correct
20 Correct 169 ms 15464 KB Output is correct
21 Correct 73 ms 13404 KB Output is correct
22 Correct 62 ms 12300 KB Output is correct
23 Correct 75 ms 13228 KB Output is correct
24 Correct 68 ms 13132 KB Output is correct
25 Correct 61 ms 12840 KB Output is correct
26 Correct 67 ms 12404 KB Output is correct
27 Correct 73 ms 13360 KB Output is correct
28 Correct 80 ms 13396 KB Output is correct
29 Correct 119 ms 13992 KB Output is correct
30 Correct 181 ms 16108 KB Output is correct
31 Correct 81 ms 14420 KB Output is correct
32 Correct 92 ms 13444 KB Output is correct
33 Correct 79 ms 13624 KB Output is correct
34 Correct 83 ms 13900 KB Output is correct
35 Correct 71 ms 13720 KB Output is correct
36 Correct 76 ms 13872 KB Output is correct
37 Correct 93 ms 14804 KB Output is correct
38 Correct 91 ms 14604 KB Output is correct
39 Correct 92 ms 14700 KB Output is correct
40 Correct 165 ms 16244 KB Output is correct
41 Correct 240 ms 18436 KB Output is correct