답안 #668648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668648 2022-12-04T10:47:12 Z Truitadepatates Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
17 ms 592 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

vector<vector<int>> adj;
vector<int> ordre;

void dfs(int actual, int anterior){
  ordre.push_back(actual);
  for (auto v : adj[actual]){
    if (v != anterior){
      dfs(v, actual);
    }
  }
}

int findEgg (int N, vector<pair<int, int>> bridges){
  adj = vector<vector<int>>(N+1);
  for(int i = 0; i < N-1; i++){
	adj[bridges[i].first].push_back(bridges[i].second);
    adj[bridges[i].second].push_back(bridges[i].first);
  }
  dfs(1, 0);
  int r = N-1, l = 1, ans = N;
  while (r >= l){
    int m = (r+l)/2;
    if (query(vector<int>(ordre.begin(), ordre.begin()+m))){
      r = m-1;
      ans = m;
    }
    else{
      l = m+1;
    }
  }
  return ordre[ans-1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 1 ms 208 KB Number of queries: 4
3 Correct 1 ms 208 KB Number of queries: 4
4 Correct 1 ms 208 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 336 KB Number of queries: 8
2 Correct 12 ms 448 KB Number of queries: 9
3 Correct 17 ms 456 KB Number of queries: 9
4 Correct 14 ms 464 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 592 KB Number of queries: 9
2 Correct 16 ms 456 KB Number of queries: 9
3 Correct 17 ms 456 KB Number of queries: 9
4 Correct 14 ms 580 KB Number of queries: 9