Submission #385713

#TimeUsernameProblemLanguageResultExecution timeMemory
385713IwanttobreakfreeEaster Eggs (info1cup17_eastereggs)C++17
0 / 100
2 ms536 KiB
#include <bits/stdc++.h> #include "grader.h" using namespace std; vector<int> c; void conexa(vector<vector<int> >& cone,int raiz,int cont,vector<bool>& visto){ visto[raiz]=true; for(int x: cone[raiz]){ if(c.size()==cont){ return; } if(!visto[x]){ c.push_back(x); conexa(cone,x,cont,visto); } } } int findEgg (int N, vector < pair < int, int > > bridges){ vector<vector<int> > cone(512,vector<int>()); for(int i=0;i<N-1;i++){ cone[bridges[i].first].push_back(bridges[i].second); cone[bridges[i].second].push_back(bridges[i].first); } int raiz,sol; vector<int> v; vector<bool> posi(N+1,true); int cont=N/2; while(cont>1){ c.clear(); for(int i=1;i<=N;i++){ if(posi[i]){ raiz=i; break; } } vector<bool> visto(N+1,false); conexa(cone,raiz,cont,visto); if(query(v)){ set<int> s; for(int i=0;i<c.size();i++)s.insert(c[i]-1); for(int i=1;i<=N;i++){ if(s.find(i)==s.end())posi[i]=false; } 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<std::vector<int> >&, int, int, std::vector<bool>&)':
eastereggs.cpp:8:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    8 |   if(c.size()==cont){
      |      ~~~~~~~~^~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for(int i=0;i<c.size();i++)s.insert(c[i]-1);
      |                ~^~~~~~~~~
eastereggs.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    for(int i=0;i<v.size();i++)posi[v[i]]=false;
      |                ~^~~~~~~~~
eastereggs.cpp:52:12: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |     return sol;
      |            ^~~
eastereggs.cpp:36:9: warning: 'raiz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |   conexa(cone,raiz,cont,visto);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...