답안 #920910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920910 2024-02-03T07:33:53 Z DON_F Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
22 ms 784 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 = 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);
        g[z[i].S].push_back(z[i].F);
    }
    while (cur.size() > 1){
        p = cur.size() / 2;
        vis = vector < int > (n + 1);
        dfs(*cur.begin());
        ll tmp = query(all);
        if (tmp){
           cur.clear();
           for (auto &i : sp){
              cur.insert(i);
           }
        }else{
           for (auto &i : sp){
             cur.erase(i);
           }
        }
        sp.clear();
        all.clear();
    }
    return *cur.begin();
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:36:9: warning: unused variable 'par' [-Wunused-variable]
   36 |     int par = -1;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 476 KB Number of queries: 8
2 Correct 11 ms 756 KB Number of queries: 9
3 Correct 20 ms 760 KB Number of queries: 9
4 Correct 18 ms 516 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 784 KB Number of queries: 9
2 Correct 18 ms 512 KB Number of queries: 9
3 Correct 20 ms 772 KB Number of queries: 9
4 Correct 22 ms 520 KB Number of queries: 9