Submission #360102

# Submission time Handle Problem Language Result Execution time Memory
360102 2021-01-27T12:57:44 Z amunduzbaev Easter Eggs (info1cup17_eastereggs) C++14
81 / 100
82 ms 1132 KB
#include <bits/stdc++.h>
#include "grader.h"
 
#ifndef EVAL
#include "grader.cpp"
#endif
 
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define pii pair<int, int>
 
using namespace std;
 
const int NN = 513;
vector<pii> edges[NN];
vector<int> vv[NN];
int nn, used[NN];
bool ok;
 
void dfs(int u, int p = -1){
	//if(ok) cout<<u<<" ";
	vv[u].pb(u);
	for(auto x:edges[u]){
		if(x.ff == p || used[x.ss]) continue;
		dfs(x.ff, u);
		for(auto xx:vv[x.ff]) vv[u].pb(xx);
	}
}
 
/*
 
13
1 2
1 5
1 6
2 3
2 4
1 7
7 8
7 9
8 10
8 11
9 12
9 13
 
5
1 3 5 9 13

3
1 2
2 3

3
1 2 3

*/
 
int dfs_cc(int u, int p = -1){
	pii mx = {-1, -1};
	for(auto x:edges[u]){
		if(used[x.ss] || x.ff == p) continue;
		if(sz(vv[x.ff]) > mx.ff) mx.ff = sz(vv[x.ff]), mx.ss = x.ff;
	}
	if(mx.ff * 2 >= nn) return dfs_cc(mx.ss, u);
	return u;
}
 
int solve(int cur){
	if(nn == 1) return cur;
	for(int i=0;i<NN;i++) vv[i].clear();
	dfs(cur);
	
	//cout<<"\n";
	//cout<<nn<<" "<<cur<<"\n";
	if(nn == 1) return 0;
	int centr = dfs_cc(cur);
	
	for(int i=0;i<NN;i++) vv[i].clear();
	dfs(centr);
	vector<pair<int, pii>> childs;
	for(auto x:edges[centr]) childs.pb({sz(vv[x.ff]), x});
	
	sort(childs.begin(), childs.end());
	vector<int> qq = vv[childs.back().ss.ff];
	qq.pb(centr);
	
	vector<int> uu(NN, 0);
	uu[childs.back().ss.ss] = 1;
	childs.pop_back();
	
	int last = -1, nw = -1;
	int start;
	for(auto x:childs){
		last = sz(qq);
		nw = x.ff + last;
		if(abs(nw*2 - nn) <= abs(nn - last*2)){
			for(auto xx : vv[x.ss.ff]) qq.pb(xx);
		}else { start = x.ss.ff; break; }
		uu[x.ss.ss] = 1;
	}
	for(auto &x:qq) x += 1;
	int res = query(qq);
	
	if(res){
		for(auto x:edges[centr]) if(!uu[x.ss])  used[x.ss] = 1;
		nn = sz(qq);
		if(nn == 2){
			if(query({qq.back()})) return qq.back()-1;
			else { qq.pop_back(); return qq.back()-1; }
		}
		if(nn == 1) return centr;
		return solve(centr);
	}
	else{
		for(auto x:edges[centr]) if(uu[x.ss]) used[x.ss] = 1;
		nn = (nn - sz(qq));
		if(nn == 1) return start;
		nn++;
		return solve(centr);
	}
}
 
int findEgg (int N, vector < pair < int, int > > bridges){
	memset(used, 0, sizeof used);
	for(int i=0;i<NN;i++) edges[i].clear(), vv[i].clear();
	nn = N;
	for(int i=0;i<sz(bridges);i++){
		edges[bridges[i].ff-1].pb({bridges[i].ss-1, i});
		edges[bridges[i].ss-1].pb({bridges[i].ff-1, i});
	}
	return solve(0)+1;
}
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 364 KB Number of queries: 5
2 Partially correct 2 ms 364 KB Number of queries: 6
3 Partially correct 1 ms 364 KB Number of queries: 5
4 Partially correct 2 ms 364 KB Number of queries: 5
# Verdict Execution time Memory Grader output
1 Correct 14 ms 492 KB Number of queries: 9
2 Partially correct 15 ms 500 KB Number of queries: 10
3 Partially correct 28 ms 620 KB Number of queries: 11
4 Partially correct 20 ms 492 KB Number of queries: 10
# Verdict Execution time Memory Grader output
1 Partially correct 82 ms 1132 KB Number of queries: 10
2 Partially correct 18 ms 492 KB Number of queries: 11
3 Partially correct 22 ms 492 KB Number of queries: 11
4 Partially correct 19 ms 492 KB Number of queries: 10