Submission #433198

# Submission time Handle Problem Language Result Execution time Memory
433198 2021-06-19T07:29:42 Z hhhhaura Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
14 ms 456 KB
#define wiwihorz
#include "grader.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)

using namespace std;

#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a) 
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
int n;
vector<vector<int>> mp;
vector<int> vis, sz, qq, cur, mx;
void get_sz(int x, int par) {
	sz[x] = 1, mx[x] = 0;
	for(auto i : mp[x]) {
		if(i == par || vis[i]) continue;
		get_sz(i, x);
		sz[x] += sz[i];
		mx[x] = max(mx[x], sz[i]);
	}
	return;
}
int get_cen(int x, int par, int tot) {
	int best = x;
	for(auto i : mp[x]) {
		if(i == par || vis[i]) continue;
		int cur = get_cen(i, x, tot);
		if(max(mx[cur], tot - sz[cur]) < 
			max(mx[best], tot - sz[best])) best = cur;
	}
	return best;
}
void put(int x, int par) {
	qq.push_back(x);
	for(auto i : mp[x]) {
		if(i == par || vis[i]) continue;
		put(i, x);
 	}
}
int dfs(int x) {
	get_sz(x, x);
	int cen = get_cen(x, x, sz[x]);
	if(sz[x] == 1) return x;
	if(query({cen})) return cen;
	cur.clear(), vis[cen] = 1;
	for(auto i : mp[cen]) if(!vis[i]) {
		cur.push_back(i);
	}
	int l = 0, r = cur.size();
	while(r - l > 1) {
		int mid = (l + r) / 2;
		qq.clear();
		rep(i, mid, r - 1) 
			put(cur[i], cur[i]); 
		if(query(qq)) l = mid;
		else r = mid;
	}
	return dfs(cur[l]);
} 
int findEgg (int N, vector<pii> bridges) {
	n = N;
	mp.assign(n + 1, vector<int>());
	vis.assign(n + 1, 0);
	sz.assign(n + 1, 0);
	mx.assign(n + 1, 0); 
	for(auto i : bridges) {
		mp[i.first].push_back(i.second);
		mp[i.second].push_back(i.first);
	}
	return dfs(1);
}

Compilation message

eastereggs.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
eastereggs.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
eastereggs.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 200 KB Number of queries: 7
2 Runtime error 1 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 7 ms 200 KB Number of queries: 15
2 Runtime error 2 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 14 ms 328 KB Number of queries: 17
2 Runtime error 2 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -