Submission #484258

# Submission time Handle Problem Language Result Execution time Memory
484258 2021-11-02T17:55:49 Z Tenis0206 Easter Eggs (info1cup17_eastereggs) C++11
81 / 100
11 ms 2632 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

int cnt = 0;

int n;

vector<int> G[100005];

int p[100005],fr[100005];

/*int ou = 0;

bool query(vector<int> v)
{
    for(auto it : v)
    {
        if(it==ou)
        {
            return true;
        }
    }
    return false;
}
*/

void dfs(int nod, int dad = 0)
{
    p[++cnt] = nod;
    for(auto it : G[nod])
    {
        if(it==dad)
        {
            continue;
        }
        dfs(it,nod);
        p[++cnt] = nod;
    }
}

vector<int> get_query(int st, int dr)
{
    vector<int> rez;
    for(int i=st;i<=dr;i++)
    {
        if(!fr[p[i]])
        {
            rez.push_back(p[i]);
        }
        ++fr[p[i]];
    }
    for(int i=st;i<=dr;i++)
    {
        fr[p[i]] = 0;
    }
    return rez;
}

int findEgg(int N, vector<pair<int,int>> e)
{
    n = N;
    for(auto it : e)
    {
        int x = it.first;
        int y = it.second;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1);
    int st = 1;
    int dr = 2 * n - 1;
    while(st<dr)
    {
        int mij = (st+dr)>>1;
        vector<int> q = get_query(st,mij);
        if(query(q))
        {
            dr = mij;
        }
        else
        {
            st = mij+1;
        }
    }
    cnt = 0;
    for(int i=1;i<=n;i++)
    {
        G[i].clear();
    }
    return p[st];
}

/*int main()
{
    int n;
    cin>>n>>ou;
    vector<pair<int,int>> e;
    for(int i=1;i<n;i++)
    {
         int x,y;
         cin>>x>>y;
         e.push_back({x,y});
    }
    cout<<findEgg(n,e);
    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2632 KB Number of queries: 5
2 Partially correct 2 ms 2632 KB Number of queries: 5
3 Partially correct 2 ms 2632 KB Number of queries: 5
4 Partially correct 2 ms 2632 KB Number of queries: 5
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2632 KB Number of queries: 9
2 Partially correct 9 ms 2632 KB Number of queries: 10
3 Partially correct 11 ms 2632 KB Number of queries: 10
4 Partially correct 10 ms 2632 KB Number of queries: 10
# Verdict Execution time Memory Grader output
1 Partially correct 11 ms 2600 KB Number of queries: 10
2 Partially correct 9 ms 2632 KB Number of queries: 10
3 Partially correct 10 ms 2632 KB Number of queries: 10
4 Partially correct 10 ms 2632 KB Number of queries: 10