Submission #61483

# Submission time Handle Problem Language Result Execution time Memory
61483 2018-07-26T05:12:18 Z tranxuanbach Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
51 ms 2808 KB
#include<bits/stdc++.h>
#include"grader.h"
using namespace std;
#define fi first
#define se second

const int N = 1e5 + 5;
vector <int> 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);
    }
    return;
}
 
int findEgg(int N, vector <pair <int, int> > 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].fi].push_back(bridges[i].se);
        adj[bridges[i].se].push_back(bridges[i].fi);
    }
    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:20: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:52:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < ans.size(); i++){
                             ~~^~~~~~~~~~~~
eastereggs.cpp:61:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < ans.size(); i++){
                             ~~^~~~~~~~~~~~
eastereggs.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2596 KB Number of queries: 4
2 Correct 6 ms 2616 KB Number of queries: 4
3 Correct 6 ms 2692 KB Number of queries: 4
4 Correct 5 ms 2752 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2756 KB Number of queries: 8
2 Correct 23 ms 2804 KB Number of queries: 9
3 Correct 34 ms 2804 KB Number of queries: 9
4 Correct 39 ms 2804 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2804 KB Number of queries: 9
2 Correct 40 ms 2808 KB Number of queries: 9
3 Correct 37 ms 2808 KB Number of queries: 9
4 Correct 37 ms 2808 KB Number of queries: 9