Submission #894018

# Submission time Handle Problem Language Result Execution time Memory
894018 2023-12-27T19:37:30 Z raphaelp Easter Eggs (info1cup17_eastereggs) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
int egg;
int query(vector<int> temp)
{
    for (int i = 0; i < temp.size(); i++)
    {
        if (temp[i] == egg)
            return 1;
    }
    return 0;
}
void dfs(int x, int p, int &targ, vector<int> &taken, vector<int> &occ, vector<vector<int>> &Tab)
{
    targ -= occ[x];
    taken.push_back(x + 1);
    if (targ == 0)
        return;
    for (int i = 0; i < Tab[x].size(); i++)
    {
        if (targ == 0)
            break;
        if (Tab[x][i] == p)
            continue;
        dfs(Tab[x][i], x, targ, taken, occ, Tab);
    }
}
int findEgg(int N, vector<pair<int, int>> bridges)
{
    vector<int> occ(N, 1);
    vector<vector<int>> Tab(N);
    for (int i = 0; i < N - 1; i++)
    {
        Tab[bridges[i].first - 1].push_back(bridges[i].second - 1);
        Tab[bridges[i].second - 1].push_back(bridges[i].first - 1);
    }
    int num = N;
    while (num > 1)
    {
        vector<int> taken;
        int targ = num / 2;
        dfs(0, 0, targ, taken, occ, Tab);
        targ = num / 2;
        int temp = query(taken);
        if (temp)
        {
            num = targ;
            sort(taken.begin(), taken.end());
            int buff = 0;
            for (int i = 0; i < N; i++)
            {
                if (buff < taken.size() && i == taken[buff] - 1)
                {
                    buff++;
                    continue;
                }
                occ[i] = 0;
            }
        }
        else
        {
            num -= targ;
            for (int i = 0; i < taken.size(); i++)
            {
                occ[taken[i] - 1] = 0;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (occ[i])
            ans = i + 1;
    }
    return ans;
}
int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> Tab;
    for (int i = 1; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        Tab.push_back({a, b});
    }
    egg = 4;
    cout << findEgg(N, Tab);
}

Compilation message

eastereggs.cpp: In function 'int query(std::vector<int>)':
eastereggs.cpp:6:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for (int i = 0; i < temp.size(); i++)
      |                     ~~^~~~~~~~~~~~~
eastereggs.cpp: In function 'void dfs(int, int, int&, std::vector<int>&, std::vector<int>&, std::vector<std::vector<int> >&)':
eastereggs.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < Tab[x].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                 if (buff < taken.size() && i == taken[buff] - 1)
      |                     ~~~~~^~~~~~~~~~~~~~
eastereggs.cpp:63:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for (int i = 0; i < taken.size(); i++)
      |                             ~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccmC84BO.o: in function `query(std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x0): multiple definition of `query(std::vector<int, std::allocator<int> >)'; /tmp/ccMtCpsM.o:eastereggs.cpp:(.text+0x380): first defined here
/usr/bin/ld: /tmp/ccmC84BO.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccMtCpsM.o:eastereggs.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status