Submission #727492

# Submission time Handle Problem Language Result Execution time Memory
727492 2023-04-20T21:11:25 Z n0sk1ll 007 (CEOI14_007) C++17
0 / 100
596 ms 33372 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];

vector<int> njeni[200005],njegovi[200005];

bool moze(int n, int ona, int on, int a, int b, int wait)
{
    fff(i,1,n) vis[i]=false;

    queue<pii> bfs;
    bfs.push({on,wait});
    while (!bfs.empty())
    {
        auto [p,d]=bfs.front(); bfs.pop();
        if (vis[p]) continue; vis[p]=true; //cout<<p<<" ";
        if (d==0) continue;
        for (auto it : g[p]) bfs.push({it,d-1});
    }

    if (vis[a]) return false;
    if (vis[b]) return false;

    ff(i,0,n) njeni[i].clear(),njegovi[i].clear();
    fff(i,1,n) if (vis[i]) njegovi[0].pb(i);
    njeni[0].pb(ona);

    fff(i,1,n) vis[i]=false;

    ff(dubina,0,n)
    {
        for (auto p : njeni[dubina])
        {
            if (vis[p]) continue;
            vis[p]=1;
            for (auto it : g[p]) njeni[dubina+1].pb(it);
        }

        for (auto p : njegovi[dubina])
        {
            if (vis[p]) continue;
            vis[p]=1;
            if (p==a) return false;
            if (p==b) return false;
            for (auto it : g[p]) njegovi[dubina+1].pb(it);
        }
    }

    return true;

}

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);
    }

    int l=-1,r=n;
    while (r-l>1)
    {
        int mid=(l+r)/2;
        if (moze(n,ona,on,a,b,mid)) l=mid;
        else r=mid;
    }

    cout<<l<<"\n";
}

//Note to self: Check for overflow

Compilation message

007.cpp: In function 'bool moze(int, int, int, int, int, int)':
007.cpp:51:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   51 |         if (vis[p]) continue; vis[p]=true; //cout<<p<<" ";
      |         ^~
007.cpp:51:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   51 |         if (vis[p]) continue; vis[p]=true; //cout<<p<<" ";
      |                               ^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14428 KB Output is correct
4 Incorrect 8 ms 14420 KB Output isn't correct
5 Incorrect 9 ms 14364 KB Output isn't correct
6 Correct 8 ms 14432 KB Output is correct
7 Correct 8 ms 14424 KB Output is correct
8 Incorrect 8 ms 14420 KB Output isn't correct
9 Correct 9 ms 14420 KB Output is correct
10 Correct 8 ms 14428 KB Output is correct
11 Correct 8 ms 14428 KB Output is correct
12 Incorrect 8 ms 14436 KB Output isn't correct
13 Correct 8 ms 14400 KB Output is correct
14 Incorrect 8 ms 14428 KB Output isn't correct
15 Correct 8 ms 14420 KB Output is correct
16 Incorrect 8 ms 14420 KB Output isn't correct
17 Incorrect 9 ms 14432 KB Output isn't correct
18 Incorrect 8 ms 14432 KB Output isn't correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 8 ms 14444 KB Output is correct
21 Correct 8 ms 14452 KB Output is correct
22 Correct 8 ms 14420 KB Output is correct
23 Correct 8 ms 14420 KB Output is correct
24 Incorrect 8 ms 14436 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 17064 KB Output is correct
2 Incorrect 53 ms 18172 KB Output isn't correct
3 Correct 45 ms 17632 KB Output is correct
4 Incorrect 63 ms 18440 KB Output isn't correct
5 Correct 43 ms 17504 KB Output is correct
6 Correct 37 ms 17612 KB Output is correct
7 Correct 47 ms 17808 KB Output is correct
8 Correct 45 ms 17812 KB Output is correct
9 Incorrect 72 ms 18188 KB Output isn't correct
10 Correct 295 ms 26884 KB Output is correct
11 Incorrect 98 ms 21092 KB Output isn't correct
12 Correct 125 ms 21044 KB Output is correct
13 Incorrect 102 ms 19064 KB Output isn't correct
14 Correct 75 ms 20532 KB Output is correct
15 Correct 115 ms 21336 KB Output is correct
16 Correct 133 ms 22344 KB Output is correct
17 Correct 110 ms 20160 KB Output is correct
18 Incorrect 106 ms 20632 KB Output isn't correct
19 Correct 199 ms 23720 KB Output is correct
20 Incorrect 382 ms 27612 KB Output isn't correct
21 Incorrect 182 ms 23932 KB Output isn't correct
22 Correct 163 ms 23420 KB Output is correct
23 Correct 202 ms 24356 KB Output is correct
24 Correct 178 ms 24728 KB Output is correct
25 Incorrect 170 ms 24428 KB Output isn't correct
26 Correct 222 ms 22472 KB Output is correct
27 Correct 172 ms 23212 KB Output is correct
28 Correct 185 ms 22880 KB Output is correct
29 Correct 276 ms 25056 KB Output is correct
30 Incorrect 429 ms 28784 KB Output isn't correct
31 Incorrect 231 ms 27708 KB Output isn't correct
32 Correct 189 ms 24284 KB Output is correct
33 Correct 203 ms 25288 KB Output is correct
34 Incorrect 234 ms 24264 KB Output isn't correct
35 Incorrect 191 ms 24756 KB Output isn't correct
36 Incorrect 182 ms 24732 KB Output isn't correct
37 Correct 299 ms 25916 KB Output is correct
38 Correct 218 ms 24228 KB Output is correct
39 Correct 270 ms 25648 KB Output is correct
40 Incorrect 389 ms 28168 KB Output isn't correct
41 Correct 596 ms 33372 KB Output is correct