Submission #288914

# Submission time Handle Problem Language Result Execution time Memory
288914 2020-09-02T07:02:56 Z andreiomd Easter Eggs (info1cup17_eastereggs) C++11
100 / 100
22 ms 416 KB
#include <vector>
#include "grader.h"

using namespace std;

typedef pair < int, int > PII;

const int NMAX = ((1 << 9) + 5);
vector < int > G[NMAX];

vector < int > List;

inline void Reset (int n)
{
    for(int i = 1; i <= n; ++i)
        if(!G[i].empty())
            G[i].clear();

    if(!List.empty())
        List.clear();

    return;
}

inline void Add_Edge (int X, int Y)
{
    G[X].push_back(Y), G[Y].push_back(X);

    return;
}

inline void DFS (int Node, int Father)
{
    List.push_back(Node);

    for(auto it : G[Node])
        if(it != Father)
            DFS(it, Node);

    return;
}

inline bool Ok (int pos)
{
    vector < int > qq;

    for(int i = 0; i <= (pos - 1); ++i)
        qq.push_back(List[i]);

    return query(qq);
}

int findEgg (int n, vector < PII > edges)
{
    Reset(n);

    for(auto it : edges)
        Add_Edge(it.first, it.second);

    int root = edges[0].first;

    DFS(root, -1);

    int Left = 1, Right = n;

    while(Left < Right)
    {
        int Mid = (Left + Right) >> 1;

        if(Ok(Mid))
            Right = Mid;
        else
            Left = Mid + 1;
    }

    return List[Left - 1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Number of queries: 4
2 Correct 1 ms 384 KB Number of queries: 4
3 Correct 1 ms 384 KB Number of queries: 4
4 Correct 1 ms 256 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Number of queries: 8
2 Correct 16 ms 384 KB Number of queries: 9
3 Correct 20 ms 384 KB Number of queries: 9
4 Correct 22 ms 384 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 21 ms 416 KB Number of queries: 9
2 Correct 20 ms 384 KB Number of queries: 9
3 Correct 19 ms 384 KB Number of queries: 9
4 Correct 20 ms 384 KB Number of queries: 9