답안 #577278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577278 2022-06-14T12:03:28 Z keta_tsimakuridze Burza (COCI16_burza) C++14
160 / 160
127 ms 9996 KB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
const int N = 403, mod = 1e9 + 7; //!
int t, dp[N][1 << 20], h[N], tmin[N], timer, tmout[N], p[N];
vector<int> v, V[N];
int n, k;
void dfs(int u) {
	h[u] = h[p[u]] + 1;
	if(h[u] == k) {
		v.push_back(u); 
		tmin[u] = tmout[u] = ++timer;
		return;
	}
	tmin[u] = n + 5;
	for(int i = 0; i < V[u].size(); i++) {
		if(V[u][i] == p[u]) continue;
		p[V[u][i]] = u;
		dfs(V[u][i]);
		tmin[u] = min(tmin[u], tmin[V[u][i]]);
	}
	tmout[u] = timer;
}
main() {
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n >> k;
	++k;
	if(k > 20) {
		cout << "DA";
		return 0;
	}
	for(int i = 2; i <= n; i++) {
		int u, v;
		cin >> u >> v;
		V[u].push_back(v);
		V[v].push_back(u);
	}
	dfs(1); 
	dp[1][0] = 1;
	for(int i = 0; i < v.size(); i++) {

		int x = v[i]; 
		while(x != 1) {
			if(tmin[x] != tmin[v[i]]) break;
			for(int j = 0; j < (1 << k); j++) {
				if(j & (1 << (h[x] - 2)) || !dp[tmin[x]][j]) continue;
				dp[tmout[x] + 1][j ^ (1 << (h[x] - 2))] = 1; 
			}
			x = p[x];
		}
	}
	int ans = 0;
	for(int j = 0; j < (1 << k); j++) ans |= dp[timer + 1][j];
	cout << (ans ? "DA" : "NE");
	
}

Compilation message

burza.cpp: In function 'void dfs(int)':
burza.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 0; i < V[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
burza.cpp: At global scope:
burza.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main() {
      | ^~~~
burza.cpp: In function 'int main()':
burza.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i = 0; i < v.size(); i++) {
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 102 ms 7640 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 1492 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 8236 KB Output is correct
2 Correct 92 ms 7372 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 97 ms 9016 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 8308 KB Output is correct
2 Correct 98 ms 7428 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3432 KB Output is correct
2 Correct 104 ms 9996 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 6492 KB Output is correct
2 Correct 88 ms 8796 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 1492 KB Output is correct
6 Correct 2 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 8344 KB Output is correct
2 Correct 103 ms 8416 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 1364 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 8628 KB Output is correct
2 Correct 90 ms 8324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 122 ms 9244 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3220 KB Output is correct
2 Correct 103 ms 8272 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1364 KB Output is correct
2 Correct 95 ms 8760 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 4648 KB Output is correct
2 Correct 105 ms 8884 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 43 ms 4600 KB Output is correct
6 Correct 1 ms 856 KB Output is correct