Submission #498758

# Submission time Handle Problem Language Result Execution time Memory
498758 2021-12-26T10:04:37 Z aihay Easter Eggs (info1cup17_eastereggs) C++14
Compilation error
0 ms 0 KB
#define pb push_back
#define f first
#define s second
int vis[513],pos[513],ch[513];
int dfs(int n,vector<int>v[513],int idx=1){
    vis[idx]=1;
    int x=1;
    for(int i=0;i<v[idx].size();i++){
        if(!vis[v[idx][i]])
            x+=dfs(n,v,v[idx][i]);
    }
    ch[idx]=x;
    return x;
}
vector<int> dfs2(int n,vector<int>v[513],int idx=1){
    vis[idx]=1;
    vector<int> ans;
    ans.pb(idx);
    for(int i=0;i<v[idx].size();i++){
        if(!vis[v[idx][i]]){
            vector<int> z=dfs2(n,v,v[idx][i]);
            for(int j=0;j<z.size();j++){
                ans.pb(z[j]);
            }
        }
    }
    return ans;
}
int findEgg (int n, vector<pair<int,int> > edg){
    memset(vis,0,sizeof vis);
    memset(pos,0,sizeof pos);
    vector<int> v[513];
    for(int i=0;i<edg.size();i++){
        v[edg[i].f].pb(edg[i].s);
        v[edg[i].s].pb(edg[i].f);
        pos[edg[i].f]=1;
        pos[edg[i].s]=1;
    }
    dfs(n,v,1);
    int x=1;
    bool bol=1;
    while(1){
        int tk[513]={0};
        vector<int> h;
        for(int i=1;i<=n;i++){
            if(pos[i])
                h.pb(i);
        }
        /*cout<<h.size()<<"\n";
        for(int i=0;i<h.size();i++){
            cout<<h[i]<<" ";
        }
        cout<<"\n\n";*/
        if(h.size()==1){
            if(bol==0&&query(h)==0)
                for(int i=1;i<=n;i++){
                    for(int j=0;j<v[i].size();j++){
                        if(v[i][j]==x){
                            return i;
                        }
                    }
                }
            break;
        }
        int a=ch[x],b=1;
        vector<int> va,vb;
        vb.pb(x);
        int zz=0;
        for(int i=0;i<v[x].size();i++){
            if(b+ch[v[x][i]]<a&&pos[v[x][i]]==1){
                zz++;
                memset(vis,0,sizeof vis);
                vis[x]=1;
                vector<int> z=dfs2(n,v,v[x][i]);
                for(int j=0;j<z.size();j++){
                    vb.pb(z[j]);
                    tk[z[j]]=1;
                }
                b+=ch[v[x][i]];
                a-=ch[v[x][i]];
            }
        }
        for(int i=1;i<=n;i++){
            if(pos[i]==1&&!tk[i]){
                va.pb(i);
            }
        }
        /*cout<<"va: "<<va.size()<<"\n";
        for(int i=0;i<va.size();i++)
            cout<<va[i]<<" ";
        cout<<"\n";
        cout<<"vb: "<<vb.size()<<"\n";
        for(int i=0;i<vb.size();i++)
            cout<<vb[i]<<" ";
        cout<<"\n\n";*/
        if(query(vb)){
            bol=0;
            memset(pos,0,sizeof pos);
            for(int i=0;i<vb.size();i++){
                pos[vb[i]]=1;
            }
            if(zz==1){
                for(int i=0;i<v[x].size();i++){
                    if(pos[v[x][i]]){
                        pos[x]=0;
                        x=v[x][i];
                        break;
                    }
                }
            }
        }
        else if((bol==0&&query(va))||bol==1){
            bol=1;
            memset(pos,0,sizeof pos);
            for(int i=0;i<va.size();i++){
                pos[va[i]]=1;
            }
            //cout<<"zz: "<<zz<<"\n";
            if(x!=1)
                zz++;
            if(zz==v[x].size()-1){
                for(int i=0;i<v[x].size();i++){
                    if(pos[v[x][i]]){
                        pos[x]=0;
                        x=v[x][i];
                        break;
                    }
                }
            }
        }
        else{
            for(int i=1;i<=n;i++){
                for(int j=0;j<v[i].size();j++){
                    if(v[i][j]==x){
                        return i;
                    }
                }
            }
        }
        bol=1;
    }
    return x;
}

Compilation message

eastereggs.cpp:5:15: error: 'vector' has not been declared
    5 | int dfs(int n,vector<int>v[513],int idx=1){
      |               ^~~~~~
eastereggs.cpp:5:21: error: expected ',' or '...' before '<' token
    5 | int dfs(int n,vector<int>v[513],int idx=1){
      |                     ^
eastereggs.cpp: In function 'int dfs(int, int)':
eastereggs.cpp:6:9: error: 'idx' was not declared in this scope
    6 |     vis[idx]=1;
      |         ^~~
eastereggs.cpp:8:19: error: 'v' was not declared in this scope
    8 |     for(int i=0;i<v[idx].size();i++){
      |                   ^
eastereggs.cpp: At global scope:
eastereggs.cpp:15:1: error: 'vector' does not name a type
   15 | vector<int> dfs2(int n,vector<int>v[513],int idx=1){
      | ^~~~~~
eastereggs.cpp:29:21: error: 'vector' has not been declared
   29 | int findEgg (int n, vector<pair<int,int> > edg){
      |                     ^~~~~~
eastereggs.cpp:29:27: error: expected ',' or '...' before '<' token
   29 | int findEgg (int n, vector<pair<int,int> > edg){
      |                           ^
eastereggs.cpp: In function 'int findEgg(int, int)':
eastereggs.cpp:30:5: error: 'memset' was not declared in this scope
   30 |     memset(vis,0,sizeof vis);
      |     ^~~~~~
eastereggs.cpp:1:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
  +++ |+#include <cstring>
    1 | #define pb push_back
eastereggs.cpp:32:5: error: 'vector' was not declared in this scope
   32 |     vector<int> v[513];
      |     ^~~~~~
eastereggs.cpp:32:12: error: expected primary-expression before 'int'
   32 |     vector<int> v[513];
      |            ^~~
eastereggs.cpp:33:19: error: 'edg' was not declared in this scope
   33 |     for(int i=0;i<edg.size();i++){
      |                   ^~~
eastereggs.cpp:34:9: error: 'v' was not declared in this scope
   34 |         v[edg[i].f].pb(edg[i].s);
      |         ^
eastereggs.cpp:39:11: error: 'v' was not declared in this scope
   39 |     dfs(n,v,1);
      |           ^
eastereggs.cpp:44:16: error: expected primary-expression before 'int'
   44 |         vector<int> h;
      |                ^~~
eastereggs.cpp:47:17: error: 'h' was not declared in this scope
   47 |                 h.pb(i);
      |                 ^
eastereggs.cpp:54:12: error: 'h' was not declared in this scope
   54 |         if(h.size()==1){
      |            ^
eastereggs.cpp:55:24: error: 'query' was not declared in this scope
   55 |             if(bol==0&&query(h)==0)
      |                        ^~~~~
eastereggs.cpp:66:16: error: expected primary-expression before 'int'
   66 |         vector<int> va,vb;
      |                ^~~
eastereggs.cpp:67:9: error: 'vb' was not declared in this scope; did you mean 'b'?
   67 |         vb.pb(x);
      |         ^~
      |         b
eastereggs.cpp:74:24: error: expected primary-expression before 'int'
   74 |                 vector<int> z=dfs2(n,v,v[x][i]);
      |                        ^~~
eastereggs.cpp:75:31: error: 'z' was not declared in this scope
   75 |                 for(int j=0;j<z.size();j++){
      |                               ^
eastereggs.cpp:85:17: error: 'va' was not declared in this scope; did you mean 'a'?
   85 |                 va.pb(i);
      |                 ^~
      |                 a
eastereggs.cpp:96:12: error: 'query' was not declared in this scope
   96 |         if(query(vb)){
      |            ^~~~~
eastereggs.cpp:112:32: error: 'va' was not declared in this scope; did you mean 'a'?
  112 |         else if((bol==0&&query(va))||bol==1){
      |                                ^~
      |                                a