Submission #45971

# Submission time Handle Problem Language Result Execution time Memory
45971 2018-04-16T17:11:41 Z minhtung0404 Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
25 ms 2952 KB
//https://oj.uz/problem/view/info1cup17_eastereggs

#include <bits/stdc++.h>
#include "grader.h"
const int N = 1e5 + 5;

using namespace std;

typedef pair <int, int> ii;
typedef vector <int> vi;

vi adj[N], ans;

int n, num, cur, cnt;
bool ck[N], nw[N];

void dfs(int u, int p){
    if (cur == num) return;
    if (ck[u]) cur++;
    ans.push_back(u);
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i];
        if (v == p) continue;
        dfs(v, u);
    }
}

int findEgg (int N, vector <ii> bridges) {
    n = N;
    for (int i = 1; i <= n; i++) ck[i] = 1; cnt = n;
    for (int i = 1; i <= n; i++) adj[i].clear();
    for (int i = 0; i < n-1; i++){
        adj[bridges[i].first].push_back(bridges[i].second);
        adj[bridges[i].second].push_back(bridges[i].first);
    }
    while (cnt != 1){
        num = (cnt + 1) / 2; cur = 0;
        ans.clear();
        dfs(1, 1);
        if (query(ans)){
            for (int i = 1; i <= n; i++) nw[i] = 0;
            for (int i = 0; i < ans.size(); i++) nw[ans[i]] = ck[ans[i]];
            for (int i = 1; i <= n; i++) ck[i] = nw[i];
            cnt = num;
        }
        else{
            for (int i = 0; i < ans.size(); i++) ck[ans[i]] = 0;
            cnt -= num;
        }
    }
    for (int i = 1; i <= n; i++) if (ck[i]) return i;
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < adj[u].size(); i++){
                     ~~^~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:30:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 1; i <= n; i++) ck[i] = 1; cnt = n;
     ^~~
eastereggs.cpp:30:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i = 1; i <= n; i++) ck[i] = 1; cnt = n;
                                             ^~~
eastereggs.cpp:42:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < ans.size(); i++) nw[ans[i]] = ck[ans[i]];
                             ~~^~~~~~~~~~~~
eastereggs.cpp:47:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < ans.size(); i++) ck[ans[i]] = 0;
                             ~~^~~~~~~~~~~~
eastereggs.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2548 KB Number of queries: 4
2 Correct 4 ms 2612 KB Number of queries: 4
3 Correct 4 ms 2688 KB Number of queries: 4
4 Correct 4 ms 2864 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2952 KB Number of queries: 8
2 Correct 17 ms 2952 KB Number of queries: 9
3 Correct 25 ms 2952 KB Number of queries: 9
4 Correct 20 ms 2952 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2952 KB Number of queries: 9
2 Correct 19 ms 2952 KB Number of queries: 9
3 Correct 22 ms 2952 KB Number of queries: 9
4 Correct 23 ms 2952 KB Number of queries: 9