Submission #920855

# Submission time Handle Problem Language Result Execution time Memory
920855 2024-02-03T06:33:55 Z DON_F Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;
using ll = long long;
#define F first
#define S second

vector < vector < int > > g;
set < int > cur, sp;
vector < int > all, vis;
int p;

void dfs(int u){
   vis[u] = 1;
   if ((int) sp.size() == p){
      return;
   }
   all.push_back(u);
   if (cur.count(u)){
     sp.insert(u);
   }
   for (auto &i : g[u]){
     if (!vis[i])
        dfs(i);
   }
}

int findEgg (int n, vector < pair < int, int > > z){
    for (int i = 0; i < n - 1; ++i){
        cin >> z[i].F >> z[i].S;
    }
    for (int i = 1; i <= n; ++i){
        cur.insert(i);
    }
    g = vector < vector < int > > (n + 1);
    vector < int > come(n + 10);
    int par = -1;
    for (int i = 0; i < n - 1; ++i){
        g[z[i].F].push_back(z[i].S);
        come[z[i].S]++;
    }
    for (int i = 1; i <= n; ++i){
         if (come[i] == 0){
            par = i;
            break;
         }
    }
    if (par == -1){
        return par;
    }
    ll last = -1;
    while (cur.size() > 1){
        p = cur.size() / 2;
        vis = vector < int > (n + 1);
        dfs(par);
        ll tmp = query(all);
        if (tmp){
           cur.clear();
           for (auto &i : sp){
              cur.insert(i);
           }
        }else{
           for (auto &i : sp){
             cur.erase(i);
           }
        }
        if (last == cur.size()){
            return -1;
        }
        last = cur.size();
        sp.clear();
        all.clear();
    }
    return *cur.begin();
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:68:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         if (last == cur.size()){
      |             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -