답안 #385716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385716 2021-04-04T19:25:01 Z Iwanttobreakfree Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
2 ms 544 KB
#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=0;
	vector<int> lista(N);
	vector<bool> visto(513,false);
	conexa(cone,bridges[0].first,N,visto);
	lista=c;
	vector<bool> posi(513,true);
	int cont=N/2;
	while(cont>0){
		c.clear();
		for(int i=0;i<N;i++){
			if(posi[lista[i]]){
				raiz=i;
				break;
			}
		}
		vector<bool> visto(513,false);
		conexa(cone,raiz,cont,visto);
		if(query(c)){
			set<int> s;
			for(int i=0;i<c.size();i++)s.insert(c[i]);
			for(int i=0;i<N;i++){
				if(s.find(lista[i])==s.end())posi[lista[i]]=false;
			}
			sol=c[0];
			cone[c[0]].clear();
			posi[c[0]]=false;
			cont/=2;
		}
		else {
			for(int i=0;i<c.size();i++)posi[c[i]]=false;
		}
	}
    return sol;
}

Compilation message

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:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    for(int i=0;i<c.size();i++)s.insert(c[i]);
      |                ~^~~~~~~~~
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<c.size();i++)posi[c[i]]=false;
      |                ~^~~~~~~~~
eastereggs.cpp:39:9: warning: 'raiz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |   conexa(cone,raiz,cont,visto);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 544 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -