Submission #786790

# Submission time Handle Problem Language Result Execution time Memory
786790 2023-07-18T12:50:55 Z borisAngelov Easter Eggs (info1cup17_eastereggs) C++17
Compilation error
0 ms 0 KB
#include "grader.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 520;

int n;

vector<int> g[maxn];

vector<int> in_order;

void dfs(int node, int par)
{
    in_order.push_back(node);

    for (auto next_node : g[node])
    {
        if (next_node != par)
        {
            dfs(next_node, node);
        }
    }
}

int findEgg(int N, vector<pair<int, int>> edges)
{
    n = N;

    for (int i = 1; i <= n; ++i)
    {
        g[i].clear();
    }

    in_order.clear();

    for (int i = 0; i < edges.size(); ++i)
    {
        int x = edges[i].first;
        int y = edges[i].second;

        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs(1, -1);

    int l = 1;
    int r = n;

    vector<int> result(maxn, -1);

    while (l <= r)
    {
        ++cnt;

        int mid = (l + r) / 2;

        vector<int> ask;

        for (int i = 0; i < mid; ++i)
        {
            ask.push_back(in_order[i]);
        }

        int curr = -1;

        if (result[mid] != -1)
        {
            curr = result[mid];
        }
        else
        {
            curr = query(ask);
        }

        if (curr == 1)
        {
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }

    return in_order[l - 1];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 0; i < edges.size(); ++i)
      |                     ~~^~~~~~~~~~~~~~
eastereggs.cpp:56:11: error: 'cnt' was not declared in this scope; did you mean 'int'?
   56 |         ++cnt;
      |           ^~~
      |           int