Submission #61482

# Submission time Handle Problem Language Result Execution time Memory
61482 2018-07-26T05:11:45 Z tranxuanbach Easter Eggs (info1cup17_eastereggs) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include"grader.h"
using namespace std;
#define fi first
#define se second
 
vector <int> adj[N], ans;
const int N = 1e5 + 5;
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:7:18: error: 'N' was not declared in this scope
 vector <int> adj[N], ans;
                  ^
eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:20:25: error: 'adj' was not declared in this scope
     for (int i = 0; i < adj[u].size(); i++){
                         ^~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:37:3: error: 'adj' was not declared in this scope
   adj[i].clear();
   ^~~
eastereggs.cpp:40:9: error: 'adj' was not declared in this scope
         adj[bridges[i].fi].push_back(bridges[i].se);
         ^~~
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]
 }
 ^