Submission #901499

# Submission time Handle Problem Language Result Execution time Memory
901499 2024-01-09T13:25:32 Z ivaziva Easter Eggs (info1cup17_eastereggs) C++14
87 / 100
12 ms 1004 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

#define MAXN 520

long long n;
vector<long long> adj[MAXN];
vector<long long> nodes;
vector<int> vec;

void dfs(long long node,long long pret)
{
    nodes.push_back(node);
    long long s=adj[node].size();
    for (long long i=0;i<s;i++)
    {
        long long sled=adj[node][i];
        if (sled!=pret) dfs(sled,node);
    }
}

bool check(long long mid)
{
    for (long i=0;i<=mid;i++) vec.push_back(nodes[i]);
    long long ans=query(vec);vec.clear();
    if (ans==1) return true;
    return false;
}

int findEgg(int N, vector < pair < int, int > > bridges)
{
    n=N;nodes.clear();
    for (long long i=0;i<MAXN;i++) adj[i].clear();
    for (long long i=0;i<n-1;i++)
    {
        long long x=bridges[i].first;
        long long y=bridges[i].second;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1,0);
    long long l=0;
    long long r=n-1;
    long long rez=-1;
    long long pretmid=-1;
    while (l<=r)
    {
        long long mid=(l+r)/2;
        if (mid==pretmid) break;
        pretmid=mid;
        if (check(mid)) {rez=mid;r=mid-1;}
        else l=mid+1;
    }
    return nodes[rez];
};
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 344 KB Number of queries: 5
2 Partially correct 1 ms 344 KB Number of queries: 5
3 Partially correct 0 ms 344 KB Number of queries: 5
4 Partially correct 1 ms 344 KB Number of queries: 5
# Verdict Execution time Memory Grader output
1 Correct 3 ms 980 KB Number of queries: 9
2 Correct 7 ms 992 KB Number of queries: 9
3 Correct 11 ms 736 KB Number of queries: 9
4 Correct 10 ms 500 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Partially correct 12 ms 1000 KB Number of queries: 10
2 Correct 9 ms 1004 KB Number of queries: 9
3 Partially correct 10 ms 736 KB Number of queries: 10
4 Partially correct 11 ms 740 KB Number of queries: 10