Submission #385703

#TimeUsernameProblemLanguageResultExecution timeMemory
385703IwanttobreakfreeEaster Eggs (info1cup17_eastereggs)C++17
0 / 100
3 ms748 KiB
#include <bits/stdc++.h> #include "grader.h" using namespace std; vector<int> c; void conexa(vector<int>& v,vector<vector<int> >& cone,int raiz,int cont,vector<bool>& visto){ visto[raiz]=true; for(int x: cone[raiz]){ if(v.size()==cont){ c=v; } if(!visto[x]){ v.push_back(x); c=v; conexa(v,cone,x,cont,visto); } } } int findEgg (int N, vector < pair < int, int > > bridges){ vector<int> lista(N); vector<vector<int> > cone(N,vector<int>()); for(int i=0;i<N-1;i++){ cone[bridges[i].first-1].push_back(bridges[i].second-1); cone[bridges[i].second-1].push_back(bridges[i].first-1); } int raiz,sol; vector<int> v; vector<bool> posi(N,true); int cont=N/2; while(cont>0){ v.clear(); for(int i=0;i<N;i++){ if(posi[i]){ raiz=i; break; } } vector<bool> visto(N,false); conexa(v,cone,raiz,cont,visto); v=c; if(query(v)){ sol=v[0]; cone[v[0]].clear(); posi[v[0]]=false; cont/=2; } else { for(int i=0;i<v.size();i++)posi[v[i]]=false; } } return sol; }

Compilation message (stderr)

eastereggs.cpp: In function 'void conexa(std::vector<int>&, std::vector<std::vector<int> >&, int, int, std::vector<bool>&)':
eastereggs.cpp:9:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    9 |   if(v.size()==cont){
      |      ~~~~~~~~^~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int i=0;i<v.size();i++)posi[v[i]]=false;
      |                ~^~~~~~~~~
eastereggs.cpp:51:12: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |     return sol;
      |            ^~~
eastereggs.cpp:39:9: warning: 'raiz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |   conexa(v,cone,raiz,cont,visto);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...