Submission #602758

# Submission time Handle Problem Language Result Execution time Memory
602758 2022-07-23T11:03:50 Z vanic Spring cleaning (CEOI20_cleaning) C++14
34 / 100
1000 ms 17000 KB
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int maxn=2e5+5;

vector < int > ms[maxn];
int novi[maxn];

int sol;
int root;

int dfs(int x, int prosl){
	int br=0;
	for(int i=0; i<(int)ms[x].size(); i++){
		if(ms[x][i]!=prosl){
			br+=dfs(ms[x][i], x);
		}
	}
	if(x==prosl){
		if(br&1){
			return 1;
		}
		return 0;
	}
	if(!br){
		br++;
	}
	if(br&1){
		sol++;
	}
	else{
		sol+=2;
	}
	return br;
}

void rijesi(){
	sol=0;
	if(dfs(root, root)){
		printf("-1\n");
		return;
	}
	printf("%d\n", sol);
}

void scan(int &a){
	a=0;
	char c=getchar_unlocked();
	while(c>='0' && c<='9'){
		a*=10;
		a+=c-'0';
		c=getchar_unlocked();
	}
}

int main(){
	int n, q;
	scan(n);
	scan(q);
	int a, b;
	for(int i=0; i<n-1; i++){
		scan(a);
		scan(b);
		a--;
		b--;
		ms[a].push_back(b);
		ms[b].push_back(a);
	}
	for(int i=0; i<n; i++){
		if(ms[i].size()>1){
			root=i;
			break;
		}
	}
	int m;
	for(int i=0; i<q; i++){
		scan(m);
		for(int j=0; j<m; j++){
			scan(a);
			a--;
			ms[a].push_back(j+n);
			ms[j+n].push_back(a);
			novi[j*2]=a;
			novi[j*2+1]=j+n;
		}
		rijesi();
		for(int j=0; j<m*2; j++){
			ms[novi[j]].pop_back();
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Execution timed out 1089 ms 5860 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 8612 KB Output is correct
2 Correct 18 ms 8612 KB Output is correct
3 Correct 19 ms 8644 KB Output is correct
4 Correct 46 ms 11064 KB Output is correct
5 Correct 61 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 9120 KB Output is correct
2 Correct 15 ms 9044 KB Output is correct
3 Correct 29 ms 14328 KB Output is correct
4 Correct 59 ms 17000 KB Output is correct
5 Correct 26 ms 13396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 6192 KB Output is correct
2 Correct 149 ms 5812 KB Output is correct
3 Correct 200 ms 5624 KB Output is correct
4 Correct 249 ms 6100 KB Output is correct
5 Correct 221 ms 6184 KB Output is correct
6 Correct 250 ms 6168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 7044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1100 ms 8148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Execution timed out 1089 ms 5860 KB Time limit exceeded
3 Halted 0 ms 0 KB -