제출 #565898

#제출 시각아이디문제언어결과실행 시간메모리
565898groshiEaster Eggs (info1cup17_eastereggs)C++17
0 / 100
13 ms1864 KiB
#include<iostream> #include<vector> #include<utility> #include "grader.h" using namespace std; struct wi{ vector<int> Q; int odw=0; int dol=0; }*w; int egg=-1; int ile=0; /*bool query(vector<int> Q) { //cout<<"pytam sie\n"; for(int i=0;i<Q.size();i++) cout<<Q[i]<<" "; int k; cin>>k; return k; }*/ void dfs(int x,int ojc) { ile++; w[x].dol=0; for(int i=0;i<w[x].Q.size();i++) { int pom=w[x].Q[i]; if(pom==ojc || w[pom].odw==1)///uwazac z odw continue; dfs(pom,x); w[x].dol+=w[pom].dol; } w[x].dol++; } vector<int> zapytaj; void dodaj(int x,int ojc) { zapytaj.push_back(x); for(int i=0;i<w[x].Q.size();i++) { int pom=w[x].Q[i]; if(pom==ojc || w[pom].odw==1) continue; dodaj(pom,x); } } void odznacz1(int x,int ojc) { w[x].odw=1; for(int i=0;i<w[x].Q.size();i++) { int pom=w[x].Q[i]; if(w[pom].odw==1 || pom==ojc) continue; odznacz1(pom,x); } } void odznacz2(int x,int ojc,int co) { w[x].odw=1; for(int i=0;i<w[x].Q.size();i++) { int pom=w[x].Q[i]; if(w[pom].odw==1 || pom==ojc || pom==co) continue; odznacz2(pom,x,co); } } void szukaj(int x) { ile=0; dfs(x,0); if(ile==1) { egg=x; return; } int gdzie=x; int ojc=0; while(true) { //cout<<gdzie<<" "<<ojc<<"\n"; int k=0; for(int i=0;i<w[gdzie].Q.size();i++) { int pom=w[gdzie].Q[i]; if(pom==ojc || w[pom].odw==1)//uwazac z odw continue; if(w[pom].dol>=ile/2) { k=1; ojc=gdzie; gdzie=pom; break; } } if(k==1) continue; break; } zapytaj.clear(); dodaj(gdzie,ojc); int k=query(zapytaj); if(k==0) { odznacz1(gdzie,ojc); szukaj(x); } else{ odznacz2(x,0,gdzie); szukaj(gdzie); } } int findEgg(int n,vector<pair<int,int> > bridges) { w=new wi[n+3]; egg=-1; for(int i=0;i<bridges.size();i++) { int x=bridges[i].first; int y=bridges[i].second; w[x].Q.push_back(y); w[y].Q.push_back(x); } szukaj(1); return egg; }

컴파일 시 표준 에러 (stderr) 메시지

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
eastereggs.cpp: In function 'void dodaj(int, int)':
eastereggs.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
eastereggs.cpp: In function 'void odznacz1(int, int)':
eastereggs.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
eastereggs.cpp: In function 'void odznacz2(int, int, int)':
eastereggs.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
eastereggs.cpp: In function 'void szukaj(int)':
eastereggs.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int i=0;i<w[gdzie].Q.size();i++)
      |                     ~^~~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:119: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]
  119 |     for(int i=0;i<bridges.size();i++)
      |                 ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...