답안 #362007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362007 2021-02-01T14:30:21 Z lukameladze Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
22 ms 572 KB
# include <bits/stdc++.h>
#include "grader.h"
#define f first
#define s second
#define pb push_back
using namespace std;
long long le,ri, mid;
vector <int> v2;
vector <long long> v1;
vector <long long> vvv[1005];
int ans;
void dfs(int a, int p) {
     v1.pb(a);
     for (int i=0; i<(int)vvv[a].size(); i++) {
          if (vvv[a][i]!=p) {
               dfs(vvv[a][i],a);
          }
     }
}
int findEgg(int n, vector <pair <int, int > > vv)
{
     for (int i=1; i<=515; i++) {
          vvv[i].clear();
     }
     v1.clear();
     v2.clear();
         for (int i=0; i<(int)vv.size(); i++) {
          vvv[vv[i].f].pb(vv[i].s);
          vvv[vv[i].s].pb(vv[i].f);
     }
     dfs(1,0);
     le=0;
     ri=(int)v1.size()-2;
     ans=-1;
     while (le<=ri) {
          mid=(le+ri)/2;
          v2.clear();
          for (int i=0; i<=mid; i++) {
               v2.pb(v1[i]);
          }
          if (query(v2)==1) {
               ans=mid;
               ri=mid-1;
          }
          else le=mid+1;
     }
     if (ans!=-1)
     return v1[ans];
     else return v1[(int)v1.size()-1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Number of queries: 4
2 Correct 1 ms 364 KB Number of queries: 4
3 Correct 1 ms 364 KB Number of queries: 4
4 Correct 1 ms 364 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 364 KB Number of queries: 8
2 Correct 17 ms 364 KB Number of queries: 9
3 Correct 22 ms 572 KB Number of queries: 9
4 Correct 22 ms 492 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 480 KB Number of queries: 9
2 Correct 16 ms 364 KB Number of queries: 9
3 Correct 20 ms 432 KB Number of queries: 9
4 Correct 19 ms 364 KB Number of queries: 9