Submission #67653

# Submission time Handle Problem Language Result Execution time Memory
67653 2018-08-15T07:45:10 Z yusufake Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
42 ms 700 KB
#include<bits/stdc++.h>

#include "grader.h"

using namespace std;

/*


static int N, X, cntQ;
static vector < int > v[1009];

int query (vector < int > h)
{
    cntQ ++;
    int ap[1009];
    if (h.empty ()) return 0;
    for (int i=1; i<=N; i++)
        ap[i] = 0;
    for (auto it = h.begin (); it != h.end (); it ++)
        ap[*it] = 1;
    queue < int > cc;
    cc.push (h[0]), ap[h[0]] = 2;
    while (!cc.empty ())
    {
        int nod = cc.front ();
        cc.pop ();
        for (auto it = v[nod].begin (); it != v[nod].end (); it ++)
            if (ap[*it] == 1)
                ap[*it] = 2, cc.push (*it);
    }
    for (int i=1; i<=N; i++)
        if (ap[i] == 1) return -1;
    for (auto it = h.begin (); it != h.end (); it ++)
        if (*it == X) return 1;
    return 0;
}

*/

#define st first
#define nd second
#define pb push_back
int H[550];
int findEgg(int n, vector < pair < int, int > > edge){
    vector < int > V[550],vv;
    int i,j,x,l,m,r;
    for(i=0;i<n-1;i++){
       V[ edge[i].st ].pb(edge[i].nd);
       V[ edge[i].nd ].pb(edge[i].st);
    }    
    queue < int > Q;
    Q.push(1);
    memset(H,0,sizeof H);
    for(; Q.size() ; ){
        x = Q.front();
        Q.pop();
        if(H[x]) continue;
        H[x] = 1;
        vv.pb(x);
        for(auto y : V[x])
            Q.push(y);
    }
    l=0; r = n-1;
    for(; l < r ;){
        m = l+r >> 1;
        vector < int > tt; 
        for(j=0;j<=m;j++) tt.pb(vv[j]);
        if(query(tt)) r = m;
        else l = m+1;
    }
    //cout << vv[l] << " ss\n";
    return vv[l];
}        

/*

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
int Queries;
vector < pair < int, int > > param;
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y);
    v[y].push_back (x);
    param.push_back ({x, y});
}
scanf ("%d", &Queries);
while (Queries --)
{
    scanf ("%d", &X), cntQ = 0;
    int Y = findEgg (N, param);
    if (X != Y)
    {
        printf ("WA %d instead of %d\n", Y, X);
        return 0;
    }
    printf ("OK %d\n", cntQ);
}
return 0;
}

*/

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:66:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         m = l+r >> 1;
             ~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Number of queries: 4
2 Correct 4 ms 440 KB Number of queries: 4
3 Correct 3 ms 440 KB Number of queries: 4
4 Correct 3 ms 440 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 8 ms 484 KB Number of queries: 8
2 Correct 17 ms 512 KB Number of queries: 9
3 Correct 27 ms 516 KB Number of queries: 9
4 Correct 29 ms 516 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 42 ms 676 KB Number of queries: 9
2 Correct 35 ms 700 KB Number of queries: 9
3 Correct 31 ms 700 KB Number of queries: 9
4 Correct 32 ms 700 KB Number of queries: 9