답안 #762216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762216 2023-06-21T05:32:48 Z salmon Easter Eggs (info1cup17_eastereggs) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;


int findEgg (int N, vector <pair<int,int>> bridges){
    set<int> notdone;
    queue<int> q;
    bool visited[1100];
	vector<int> adjlst[1100];
	vector<int> quer;
	int goal;
		 
    for(int i = 1; i <= N; i++){
		visited[i] = false;
		adjlst[i].clear();
		notdone.insert(i);
	}
	
	quer.clear();
	
	for(int i = 0; i <  N - 1; i++){
		adjlst[bridges[i].first].push_back(bridges[i].second);
		adjlst[bridges[i].second].push_back(bridges[i].first);
	}
	
	while(notdone.size() != 1){
		int sise = notdone.size();
		goal = sise/2;
		
		for(auto i : notdone){
			bool flag = false;
			
			if(sise != N){
				for(int j : adjlst[i]){
					if(notdone.find(j) == notdone.end()){
						flag = true;
						break;
					}
				}
			}
			else{
				flag = true;
			}
			
			if(flag){
				q.push(i);
				while(!q.empty()){
					int i = q.front();
					q.pop();
					if(visited[i]) continue;
					if(goal == 0) continue;
					visited[i] = true;
					
					goal--;
					
					quer.push_back(i);
					
					for(int j : adjlst[i]){
						q.push(j);
					}
				}
			}
		}
		
		if(goal != 0){
			visited[-100102] = true;
		}

		/*printf("q: ");
		for(auto i : quer){
			printf("%d ",i);
		}
		printf("\n");*/
		
		int con = quer.size();
		
		if(query(quer)){
			for(auto i : notdone){
				visited[i] = true;
			}
			notdone.insert(quer[i]);
				visited[quer[i]] = false;
				quer.pop_back();
			}
		}
		else{
			for(int i = quer.size() - 1; i > con - 1 - sise/2; i--){
				notdone.erase(quer[i]);
			}
		}
		
		/*for(auto i : notdone){
			printf("%d ",i);
		}
		printf("\n");*/
	}
	
	return (*notdone.begin());
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:82:24: error: 'i' was not declared in this scope
   82 |    notdone.insert(quer[i]);
      |                        ^
eastereggs.cpp:76:7: warning: unused variable 'con' [-Wunused-variable]
   76 |   int con = quer.size();
      |       ^~~
eastereggs.cpp:87:3: error: 'else' without a previous 'if'
   87 |   else{
      |   ^~~~
eastereggs.cpp:88:37: error: 'con' was not declared in this scope; did you mean 'cos'?
   88 |    for(int i = quer.size() - 1; i > con - 1 - sise/2; i--){
      |                                     ^~~
      |                                     cos
eastereggs.cpp:88:47: error: 'sise' was not declared in this scope
   88 |    for(int i = quer.size() - 1; i > con - 1 - sise/2; i--){
      |                                               ^~~~
eastereggs.cpp:97:2: warning: no return statement in function returning non-void [-Wreturn-type]
   97 |  }
      |  ^
eastereggs.cpp: At global scope:
eastereggs.cpp:99:2: error: expected unqualified-id before 'return'
   99 |  return (*notdone.begin());
      |  ^~~~~~
eastereggs.cpp:100:1: error: expected declaration before '}' token
  100 | }
      | ^