Submission #498744

# Submission time Handle Problem Language Result Execution time Memory
498744 2021-12-26T09:38:01 Z aihay Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
3 ms 584 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

#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;
    while(1){
        int tk[513]={0};
        vector<int> h;
        for(int i=1;i<=n;i++){
            if(pos[i])
                h.pb(i);
        }
        if(h.size()==1){
            if(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);
            }
        }
        if(query(vb)){
            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(query(va)){
            memset(pos,0,sizeof pos);
            for(int i=0;i<va.size();i++){
                pos[va[i]]=1;
            }
            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;
                    }
                }
            }
        }
    }
    return x;
}

Compilation message

eastereggs.cpp: In function 'int dfs(int, std::vector<int>*, int)':
eastereggs.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<v[idx].size();i++){
      |                 ~^~~~~~~~~~~~~~
eastereggs.cpp: In function 'std::vector<int> dfs2(int, std::vector<int>*, int)':
eastereggs.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<v[idx].size();i++){
      |                 ~^~~~~~~~~~~~~~
eastereggs.cpp:27:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             for(int j=0;j<z.size();j++){
      |                         ~^~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<edg.size();i++){
      |                 ~^~~~~~~~~~~
eastereggs.cpp:56:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |                     for(int j=0;j<v[i].size();j++){
      |                                 ~^~~~~~~~~~~~
eastereggs.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for(int i=0;i<v[x].size();i++){
      |                     ~^~~~~~~~~~~~
eastereggs.cpp:74:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |                 for(int j=0;j<z.size();j++){
      |                             ~^~~~~~~~~
eastereggs.cpp:89:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for(int i=0;i<vb.size();i++){
      |                         ~^~~~~~~~~~
eastereggs.cpp:93:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |                 for(int i=0;i<v[x].size();i++){
      |                             ~^~~~~~~~~~~~
eastereggs.cpp:104:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |             for(int i=0;i<va.size();i++){
      |                         ~^~~~~~~~~~
eastereggs.cpp:109:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |             if(zz==v[x].size()-1){
      |                ~~^~~~~~~~~~~~~~~
eastereggs.cpp:110:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |                 for(int i=0;i<v[x].size();i++){
      |                             ~^~~~~~~~~~~~
eastereggs.cpp:121:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |                 for(int j=0;j<v[i].size();j++){
      |                             ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 456 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 456 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 584 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -