Submission #486350

# Submission time Handle Problem Language Result Execution time Memory
486350 2021-11-11T10:56:20 Z NintsiChkhaidze Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
18 ms 448 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);
    }
    
    cnt=0;
    dfs(1,1);
    int l = 1,r = n,ANS=0;
    
    while(l <= r){
        int mid = (l+r)>>1;
        if (mid == n){
            ANS = in[n];
            r = n - 1;
            continue;
        }
        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++){
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 200 KB Number of queries: 4
2 Correct 2 ms 200 KB Number of queries: 4
3 Correct 2 ms 200 KB Number of queries: 4
4 Correct 2 ms 200 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Number of queries: 8
2 Correct 16 ms 328 KB Number of queries: 9
3 Correct 16 ms 344 KB Number of queries: 9
4 Correct 16 ms 328 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 18 ms 356 KB Number of queries: 9
2 Correct 18 ms 448 KB Number of queries: 9
3 Correct 17 ms 344 KB Number of queries: 9
4 Correct 17 ms 340 KB Number of queries: 9