답안 #486345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486345 2021-11-11T10:53:32 Z NintsiChkhaidze Easter Eggs (info1cup17_eastereggs) C++14
87 / 100
18 ms 480 KB
#include <bits/stdc++.h>
#include "grader.h"
#define pb push_back

using namespace std;
vector <int> v[525];
int in[525],cnt;

void dfs(int x,int par){
    in[++cnt] = x;
    for (int j=0;j<v[x].size();j++){
        int to = v[x][j];
        if (to == par) continue;
        dfs(to,x);
    }
}

int findEgg (int n, vector < pair < int, int > > vec){
    for (int i=0;i<vec.size();i++){
        int a = vec[i].first,b = vec[i].second;
        v[a].pb(b),v[b].pb(a);
    }
    
    int ANS=0;
    cnt=0;
    dfs(1,1);
    int l = 1,r = n;
    
    while(l <= r){
        int mid = (l+r)>>1;
        vector <int> q; q.clear();
        for (int i = 1; i <= mid; i++)
            q.pb(in[i]);
        
        bool check = query(q);
        if (check) {
            ANS = in[mid];
            r = mid - 1;
        }
        else l = mid + 1;
    }
    for (int i=1;i<=n;i++)
        v[i].clear(),in[i]=0;

    return ANS;
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int j=0;j<v[x].size();j++){
      |                  ~^~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i=0;i<vec.size();i++){
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 200 KB Number of queries: 5
2 Partially correct 3 ms 200 KB Number of queries: 5
3 Partially correct 1 ms 200 KB Number of queries: 5
4 Partially correct 4 ms 200 KB Number of queries: 5
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 328 KB Number of queries: 9
2 Correct 10 ms 328 KB Number of queries: 9
3 Correct 16 ms 332 KB Number of queries: 9
4 Correct 16 ms 328 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Partially correct 18 ms 360 KB Number of queries: 10
2 Correct 15 ms 336 KB Number of queries: 9
3 Partially correct 18 ms 352 KB Number of queries: 10
4 Partially correct 16 ms 480 KB Number of queries: 10