답안 #894019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894019 2023-12-27T19:38:41 Z raphaelp Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
17 ms 1228 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
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;
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int, int&, std::vector<int>&, std::vector<int>&, std::vector<std::vector<int> >&)':
eastereggs.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < Tab[x].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:43:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |                 if (buff < taken.size() && i == taken[buff] - 1)
      |                     ~~~~~^~~~~~~~~~~~~~
eastereggs.cpp:54:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for (int i = 0; i < taken.size(); i++)
      |                             ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 732 KB Number of queries: 8
2 Correct 13 ms 1228 KB Number of queries: 9
3 Correct 16 ms 984 KB Number of queries: 9
4 Correct 15 ms 500 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1040 KB Number of queries: 9
2 Correct 15 ms 984 KB Number of queries: 9
3 Correct 15 ms 728 KB Number of queries: 9
4 Correct 14 ms 748 KB Number of queries: 9