답안 #918168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918168 2024-01-29T13:21:41 Z vjudge1 Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
15 ms 5928 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
const int N=2e5+5, mod=1e9+7;
 
int n;
 
#include "grader.h"
 
vector<int> d , g[N];
 
void dfs(int s,int p) {
    d.push_back(s);
    for(auto i: g[s]) {
        if(i == p) {
            continue;
        }
        dfs(i,s);
    }
}
 
int findEgg(int M , vector<pair<int , int>> a) {
    d.clear();
    n = M;
    for(int i=0;i<=n;i++) {
        g[i].clear();
    }
    for(int i=0;i<(int)a.size();i++) {
        g[a[i].first].push_back(a[i].second);
        g[a[i].second].push_back(a[i].first);
    }
    dfs(1 , 0);
    int l = 0 , r = n - 1 , best = 0;
    while(l < r) {
        int mid = (l + r)/2;
        vector<int> q;
        for(int i=0;i<=mid;i++) {
            q.push_back(d[i]);
        }
        if(query(q) == 1) {
            r = mid;
            best = mid;
        }
        else {
            l = mid + 1;
        }
    }
    return d[l];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:35:29: warning: variable 'best' set but not used [-Wunused-but-set-variable]
   35 |     int l = 0 , r = n - 1 , best = 0;
      |                             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Number of queries: 4
2 Correct 2 ms 4952 KB Number of queries: 4
3 Correct 2 ms 4952 KB Number of queries: 4
4 Correct 2 ms 4952 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5668 KB Number of queries: 8
2 Correct 10 ms 5928 KB Number of queries: 9
3 Correct 15 ms 5680 KB Number of queries: 9
4 Correct 15 ms 5180 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 5456 KB Number of queries: 9
2 Correct 15 ms 5176 KB Number of queries: 9
3 Correct 13 ms 5676 KB Number of queries: 9
4 Correct 15 ms 5696 KB Number of queries: 9