답안 #242991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242991 2020-06-30T07:06:53 Z nnnnnnnnnnnnnnnn Easter Eggs (info1cup17_eastereggs) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "grader.h"
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
int n,cnt;
vector<vi> graph;
vi node;
vi no,yes;
void dfs(int start,int pa)
{
	int i,j;
	if(cnt==mid)		return;
	node.push_back(start);
	if(no[start]==0)	++cnt;
	for(i=0;i<graph[start].size();++i)
	{
		j = graph[start][i];
		if(j!=pa)
		{
			dfs(j,start);
		}
	}
}
int findEgg(int n,vector<ii> edge)
{
	int i,j;
	graph.assign(n+1,vi());
	no.assign(n+1,0);
	yes.assign(n+1,0);
	for(i=0;i<n;++i)
	{
		graph[edge[i].first].push_back(edge[i].second);
		graph[edge[i].second].push_back(edge[i].first);
	}
	int curr = n;
	while(curr!=1)
	{
		node.clear();
		mid = curr/2;
		cnt = 0;
		dfs(1,-1);
		if(query(node)==false)
		{
			for(i=0;i<node.size();++i)
			{
				no[node[i]] = 1;
			}
			curr -= node.size();
		}
		else
		{
			for(i=0;i<node.size();++i)
			{
				if(no[node[i]]==0)
				{
					yes[node[i]] = 1;
				}
			}
			curr = mid;
		}
	}
	for(i=1;i<=n;++i)	
	{
		if(no[i]==0&&yes[i]==1)
		{
			return i;
		}
	}
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:14:10: error: 'mid' was not declared in this scope
  if(cnt==mid)  return;
          ^~~
eastereggs.cpp:17:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<graph[start].size();++i)
          ~^~~~~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:41:3: error: 'mid' was not declared in this scope
   mid = curr/2;
   ^~~
eastereggs.cpp:46:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(i=0;i<node.size();++i)
            ~^~~~~~~~~~~~
eastereggs.cpp:54:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(i=0;i<node.size();++i)
            ~^~~~~~~~~~~~
eastereggs.cpp:28:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j;
        ^
eastereggs.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^