답안 #385703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385703 2021-04-04T18:52:21 Z Iwanttobreakfree Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
3 ms 748 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;
		}
		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

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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 748 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -