Submission #774761

# Submission time Handle Problem Language Result Execution time Memory
774761 2023-07-06T02:45:23 Z bachhoangxuan Amusement Park (JOI17_amusement_park) C++17
100 / 100
20 ms 5840 KB
#include "Joi.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second

void Joi(int N, int M, int A[], int B[], long long X, int T) {
    vector<vector<int>> adj(N),edge(N);
    for(int i=0;i<M;i++) edge[A[i]].push_back(B[i]),edge[B[i]].push_back(A[i]);
    vector<bool> vis(N,false);
    int cur=0;
    vector<int> deg(N,0),num(N,-1);
    vector<pii> pp;
    function<void(int)> dfs = [&](int u){
        vis[u]=true;
        if(cur<60) num[u]=cur++;
        for(int v:edge[u]){
            if(vis[v]) continue;
            adj[u].push_back(v);
            if(cur<60){
                pp.push_back({u,v});
                deg[u]++;deg[v]++;
            }
            dfs(v);
        }
    };
    dfs(0);
    function<void(int,int)> dfs2 = [&](int u,int p){
        pii del={-1,-1},add={-1,-1};
        if(num[u]==-1){
            for(int i=0;i<(int)pp.size();i++){
                int v1=pp[i].fi,v2=pp[i].se;
                if(deg[v1]==1 && v1!=p){
                    num[u]=num[v1];del=pp[i];
                    pp.erase(pp.begin()+i);break;
                }
                else if(deg[v2]==1 && v2!=p){
                    num[u]=num[v2];del=pp[i];
                    pp.erase(pp.begin()+i);break;
                }
            }
            deg[del.fi]--;deg[del.se]--;
            pp.push_back({p,u});add={p,u};
            deg[p]++;deg[u]++;
        }
        for(int v:adj[u]) dfs2(v,u);
        if(del.fi!=-1){
            deg[add.fi]--;deg[add.se]--;
            for(int i=0;i<(int)pp.size();i++){
                if(pp[i]==add){pp.erase(pp.begin()+i);break;}
            }
            pp.push_back(del);
            deg[del.fi]++;deg[del.se]++;
        }
    };
    dfs2(0,0);
    for(int i=0;i<N;i++) MessageBoard(i,(X>>num[i])&1);
}
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    vector<vector<int>> adj(N),edge(N);
    for(int i=0;i<M;i++) edge[A[i]].push_back(B[i]),edge[B[i]].push_back(A[i]);
    vector<bool> vis(N,false);
    int cur=0;
    vector<int> deg(N,0),num(N,-1);
    vector<pii> pp;
    function<void(int)> dfs = [&](int u){
        vis[u]=true;
        if(cur<60) num[u]=cur++;
        for(int v:edge[u]){
            if(vis[v]) continue;
            adj[u].push_back(v);
            if(cur<60){
                pp.push_back({u,v});
                deg[u]++;deg[v]++;
            }
            dfs(v);
        }
    };
    dfs(0);
    long long res=0;
    function<void(int,int)> cal = [&](int u,int p){
        for(int v:edge[u]){
            if(v==p) continue;
            int a=Move(v);
            res|=(1LL<<num[v])*a;cal(v,u);
        }
        if(p!=-1) Move(p);
    };
    function<void()> solve = [&](){
        for(int i=0;i<N;i++) edge[i].clear();
        for(auto &[u,v]:pp) edge[u].push_back(v),edge[v].push_back(u);
        res|=(1LL<<num[P])*V;
        cal(P,-1);
    };
    function<void(int,int)> dfs2 = [&](int u,int p){
        pii del={-1,-1},add={-1,-1};
        if(num[u]==-1){
            for(int i=0;i<(int)pp.size();i++){
                int v1=pp[i].fi,v2=pp[i].se;
                if(deg[v1]==1 && v1!=p){
                    num[u]=num[v1];del=pp[i];
                    pp.erase(pp.begin()+i);break;
                }
                else if(deg[v2]==1 && v2!=p){
                    num[u]=num[v2];del=pp[i];
                    pp.erase(pp.begin()+i);break;
                }
            }
            deg[del.fi]--;deg[del.se]--;
            pp.push_back({p,u});add={p,u};
            deg[p]++;deg[u]++;
        }
        if(u==P) solve();
        for(int v:adj[u]) dfs2(v,u);
        if(del.fi!=-1){
            deg[add.fi]--;deg[add.se]--;
            for(int i=0;i<(int)pp.size();i++){
                if(pp[i]==add){pp.erase(pp.begin()+i);break;}
            }
            pp.push_back(del);
            deg[del.fi]++;deg[del.se]++;
        }
    };
    dfs2(0,0);
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 688 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 1 ms 788 KB Output is correct
4 Correct 0 ms 620 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 1 ms 784 KB Output is correct
8 Correct 1 ms 784 KB Output is correct
9 Correct 1 ms 776 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 3 ms 972 KB Output is correct
12 Correct 0 ms 516 KB Output is correct
13 Correct 1 ms 788 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 1 ms 732 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 744 KB Output is correct
18 Correct 2 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5632 KB Output is correct
2 Correct 19 ms 5644 KB Output is correct
3 Correct 20 ms 5644 KB Output is correct
4 Correct 13 ms 3496 KB Output is correct
5 Correct 13 ms 4676 KB Output is correct
6 Correct 14 ms 4180 KB Output is correct
7 Correct 14 ms 4312 KB Output is correct
8 Correct 14 ms 4372 KB Output is correct
9 Correct 14 ms 4388 KB Output is correct
10 Correct 12 ms 3508 KB Output is correct
11 Correct 12 ms 3516 KB Output is correct
12 Correct 12 ms 3200 KB Output is correct
13 Correct 12 ms 3204 KB Output is correct
14 Correct 13 ms 3248 KB Output is correct
15 Correct 13 ms 3744 KB Output is correct
16 Correct 13 ms 3612 KB Output is correct
17 Correct 13 ms 3568 KB Output is correct
18 Correct 13 ms 3496 KB Output is correct
19 Correct 14 ms 3516 KB Output is correct
20 Correct 11 ms 4508 KB Output is correct
21 Correct 11 ms 4528 KB Output is correct
22 Correct 13 ms 4024 KB Output is correct
23 Correct 13 ms 4264 KB Output is correct
24 Correct 13 ms 4020 KB Output is correct
25 Correct 13 ms 4268 KB Output is correct
26 Correct 14 ms 4328 KB Output is correct
27 Correct 14 ms 4284 KB Output is correct
28 Correct 14 ms 4368 KB Output is correct
29 Correct 12 ms 3992 KB Output is correct
30 Correct 13 ms 4012 KB Output is correct
31 Correct 1 ms 656 KB Output is correct
32 Correct 1 ms 644 KB Output is correct
33 Correct 1 ms 752 KB Output is correct
34 Correct 1 ms 616 KB Output is correct
35 Correct 1 ms 524 KB Output is correct
36 Correct 1 ms 628 KB Output is correct
37 Correct 1 ms 524 KB Output is correct
38 Correct 1 ms 524 KB Output is correct
39 Correct 0 ms 600 KB Output is correct
40 Correct 1 ms 516 KB Output is correct
41 Correct 1 ms 516 KB Output is correct
42 Correct 1 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 516 KB Output is correct
2 Correct 1 ms 644 KB Output is correct
3 Correct 1 ms 648 KB Output is correct
4 Correct 2 ms 1540 KB Output is correct
5 Correct 2 ms 1456 KB Output is correct
6 Correct 2 ms 1456 KB Output is correct
7 Correct 2 ms 1460 KB Output is correct
8 Correct 2 ms 1452 KB Output is correct
9 Correct 11 ms 5840 KB Output is correct
10 Correct 11 ms 5784 KB Output is correct
11 Correct 11 ms 5760 KB Output is correct
12 Correct 0 ms 516 KB Output is correct
13 Correct 0 ms 516 KB Output is correct
14 Correct 1 ms 516 KB Output is correct
15 Correct 0 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5620 KB Output is correct
2 Correct 20 ms 5668 KB Output is correct
3 Correct 20 ms 5656 KB Output is correct
4 Correct 13 ms 3480 KB Output is correct
5 Correct 13 ms 5272 KB Output is correct
6 Correct 14 ms 4400 KB Output is correct
7 Correct 14 ms 4236 KB Output is correct
8 Correct 14 ms 4016 KB Output is correct
9 Correct 15 ms 4148 KB Output is correct
10 Correct 14 ms 3500 KB Output is correct
11 Correct 12 ms 3504 KB Output is correct
12 Correct 12 ms 3232 KB Output is correct
13 Correct 12 ms 3164 KB Output is correct
14 Correct 13 ms 3212 KB Output is correct
15 Correct 13 ms 3740 KB Output is correct
16 Correct 13 ms 3752 KB Output is correct
17 Correct 13 ms 3500 KB Output is correct
18 Correct 13 ms 3508 KB Output is correct
19 Correct 13 ms 3468 KB Output is correct
20 Correct 11 ms 4528 KB Output is correct
21 Correct 11 ms 4508 KB Output is correct
22 Correct 14 ms 4160 KB Output is correct
23 Correct 14 ms 4148 KB Output is correct
24 Correct 13 ms 4160 KB Output is correct
25 Correct 14 ms 4272 KB Output is correct
26 Correct 13 ms 4256 KB Output is correct
27 Correct 13 ms 4532 KB Output is correct
28 Correct 14 ms 4020 KB Output is correct
29 Correct 12 ms 4004 KB Output is correct
30 Correct 13 ms 4148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5640 KB Output is correct
2 Correct 20 ms 5672 KB Output is correct
3 Correct 19 ms 5588 KB Output is correct
4 Correct 13 ms 3504 KB Output is correct
5 Correct 13 ms 5564 KB Output is correct
6 Correct 14 ms 4128 KB Output is correct
7 Correct 13 ms 4016 KB Output is correct
8 Correct 14 ms 4416 KB Output is correct
9 Correct 14 ms 4324 KB Output is correct
10 Correct 12 ms 3528 KB Output is correct
11 Correct 12 ms 3512 KB Output is correct
12 Correct 15 ms 3472 KB Output is correct
13 Correct 12 ms 3224 KB Output is correct
14 Correct 15 ms 3220 KB Output is correct
15 Correct 13 ms 3748 KB Output is correct
16 Correct 13 ms 3764 KB Output is correct
17 Correct 14 ms 3504 KB Output is correct
18 Correct 13 ms 3516 KB Output is correct
19 Correct 13 ms 3508 KB Output is correct
20 Correct 11 ms 4496 KB Output is correct
21 Correct 11 ms 4536 KB Output is correct
22 Correct 13 ms 4288 KB Output is correct
23 Correct 13 ms 4080 KB Output is correct
24 Correct 14 ms 4020 KB Output is correct
25 Correct 13 ms 4144 KB Output is correct
26 Correct 13 ms 4008 KB Output is correct
27 Correct 13 ms 4500 KB Output is correct
28 Correct 13 ms 4532 KB Output is correct
29 Correct 13 ms 4236 KB Output is correct
30 Correct 13 ms 4212 KB Output is correct
31 Correct 1 ms 608 KB Output is correct
32 Correct 1 ms 772 KB Output is correct
33 Correct 1 ms 784 KB Output is correct
34 Correct 0 ms 644 KB Output is correct
35 Correct 2 ms 652 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 0 ms 516 KB Output is correct
38 Correct 0 ms 512 KB Output is correct
39 Correct 0 ms 524 KB Output is correct
40 Correct 0 ms 524 KB Output is correct
41 Correct 1 ms 524 KB Output is correct
42 Correct 0 ms 516 KB Output is correct