답안 #974786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974786 2024-05-03T19:16:30 Z AliHasanli Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
228 ms 131072 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
vector<int>dfsorder;
vector<int>g[600];
void dfs(int source,int p)
{
	dfsorder.push_back(source);
	for(int i=0;i<g[source].size();i++)
		if(g[source][i]!=p)dfs(g[source][i],source);
}
int findEgg (int N,vector<pair<int,int> >bridges)
{
    for(int i=0;i<N-1;i++)
    {
    	g[bridges[i].first].push_back(bridges[i].second);
    	g[bridges[i].second].push_back(bridges[i].first);
	}
	dfs(1,0);
	int l=1,r=N;
	int ans=0,mid;
	while(l<=r)
	{
		mid=(l+r)/2;
		if(query(vector<int>(dfsorder.begin(),dfsorder.begin()+mid)))
			r=mid-1,ans=mid;
		else l=mid+1;
	}
	
    return dfsorder[mid];
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:9:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  for(int i=0;i<g[source].size();i++)
      |              ~^~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:21:6: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
   21 |  int ans=0,mid;
      |      ^~~
eastereggs.cpp:30:24: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     return dfsorder[mid];
      |                        ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 832 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 228 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 183 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -