답안 #385707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385707 2021-04-04T19:04:45 Z Iwanttobreakfree Easter Eggs (info1cup17_eastereggs) C++17
컴파일 오류
0 ms 0 KB
#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;
			return;
		}
		if(!visto[x]){
			v.push_back(x+1);
			c=v;
			conexa(v,cone,x,cont,visto);
		}
	}
}
int findEgg (int N, vector < pair < int, int > > bridges){
	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>1){
		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)){
			set<int> s
			for(int i=0;i<v.size();i++)s.insert(v[i]-1);
			for(int i=0;i<N;i++){
				if(s.find(i)==s.end())posi[i]=false;
			}
			sol=v[0]-1;
			cone[v[0]-1].clear();
			posi[v[0]-1]=false;
			cont/=2;
		}
		else {
			for(int i=0;i<v.size();i++)posi[v[i]-1]=false;
		}
	}
    return sol;
}

Compilation message

eastereggs.cpp: In function 'void conexa(std::vector<int>&, 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(v.size()==cont){
      |      ~~~~~~~~^~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:42:4: error: expected initializer before 'for'
   42 |    for(int i=0;i<v.size();i++)s.insert(v[i]-1);
      |    ^~~
eastereggs.cpp:42:16: error: 'i' was not declared in this scope
   42 |    for(int i=0;i<v.size();i++)s.insert(v[i]-1);
      |                ^
eastereggs.cpp:44:8: error: 's' was not declared in this scope
   44 |     if(s.find(i)==s.end())posi[i]=false;
      |        ^
eastereggs.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for(int i=0;i<v.size();i++)posi[v[i]-1]=false;
      |                ~^~~~~~~~~