답안 #319386

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319386 2020-11-05T05:42:04 Z shaf_wa_nur Easter Eggs (info1cup17_eastereggs) C++14
87 / 100
24 ms 492 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

int findEgg(int n, vector<pair<int, int>> edges) {
  vector<vector<int>> g(n + 1);
  for (auto p : edges) {
    int u = p.first;
    int v = p.second;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> order;
  function<void(int, int)> dfs = [&](int u, int p) {
    order.push_back(u);
    for (int v : g[u]) {
      if (v != p) {
        dfs(v, u);
      }
    }
  };
  dfs(1, 0);
  int m = (int) order.size();
  int id = m;
  int lo = 0, hi = m - 1;

  auto ok = [&](int x) {
    vector<int> c;
    for (int i = 0; i <= x; i++) {
      c.push_back(order[i]); 
    }
    return query(c);
  };
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (ok(mid)) {
      id = mid;
      hi = mid - 1;
    }
    else {
      lo = mid + 1;
    }
  }
  return order[id];
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 364 KB Number of queries: 5
2 Partially correct 1 ms 364 KB Number of queries: 5
3 Partially correct 1 ms 364 KB Number of queries: 5
4 Partially correct 1 ms 364 KB Number of queries: 5
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 492 KB Number of queries: 9
2 Correct 15 ms 364 KB Number of queries: 9
3 Correct 24 ms 364 KB Number of queries: 9
4 Correct 20 ms 364 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Partially correct 23 ms 364 KB Number of queries: 10
2 Correct 20 ms 364 KB Number of queries: 9
3 Partially correct 21 ms 364 KB Number of queries: 10
4 Partially correct 20 ms 384 KB Number of queries: 10