답안 #319323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319323 2020-11-04T18:26:49 Z tushar_2658 Easter Eggs (info1cup17_eastereggs) C++14
87 / 100
24 ms 492 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

const int maxn = 513;

vector<int> edges[maxn];
int st[maxn], vert[maxn], timer = 0;

void dfs(int x, int p){
  st[x] = ++timer;
  vert[timer] = x;
  for(auto i : edges[x]){
    if(i != p){
      dfs(i, x);
    }
  }
}

int ask(int x){
  vector<int> v;
  for(int i = 1; i <= x; ++i){
    v.push_back(vert[i]);
  }
  int ret = query(v);
  return ret;
}

int findEgg (int N, vector < pair < int, int > > bridges)
{
  for(int i = 1; i <= N; ++i){
    edges[i].clear();
    st[i] = vert[i] = 0;
  }
  timer = 0;
  for(auto i : bridges){
    edges[i.first].push_back(i.second);
    edges[i.second].push_back(i.first);
  }
  dfs(1, 1);
  int lo = 1, hi = N, ans = 1;
  while(lo <= hi){
    int  mid = (lo + hi) >> 1;
    if(ask(mid)){
      ans = mid;
      hi = mid - 1;
    }else {
      lo = mid + 1;
    }
  }
  return vert[ans];
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 364 KB Number of queries: 5
2 Partially correct 1 ms 384 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 6 ms 364 KB Number of queries: 9
2 Correct 14 ms 432 KB Number of queries: 9
3 Correct 24 ms 492 KB Number of queries: 9
4 Correct 18 ms 364 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Partially correct 23 ms 456 KB Number of queries: 10
2 Correct 22 ms 440 KB Number of queries: 9
3 Partially correct 20 ms 364 KB Number of queries: 10
4 Partially correct 19 ms 364 KB Number of queries: 10