답안 #229246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229246 2020-05-03T22:46:58 Z MetB Burza (COCI16_burza) C++14
16 / 160
875 ms 26096 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
 
#define N 1000003
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;

int n, k, ptr;
bitset <1 << 21> d[400];

vector <int> g[N];
vector < pair <int, int> > v[400];

pair <int, int> dfs (int x, int p, int h) {
	if (h == k) {
		if (h) v[++ptr].push_back ({ptr, h - 1});
		return {ptr, ptr};
	}

	int l = 0, r = 0;

	for (int to : g[x]) {
		if (to != p) {
			auto a = dfs (to, x, h + 1);
			if (!l) l = a.first;
			r = a.second;
		}
	}

	if (h && l) v[r].push_back ({l, h - 1});

	return {l, r};
}

int main () {
	cin >> n >> k;

	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back (b);
		g[b].push_back (a);
	}

	if (k * k >= n) {
		cout << "DA";
		return 0;
	}

	dfs (0, -1, 0);

	d[0][0] = 1;
	for (int i = 1; i <= ptr; i++) {
		for (int j = 1; j < (1 << k); j++) {
			for (int b = 0; b < k; b++)
				if (j & (1 << b)) d[i][j] = d[i][j] | d[i][j - (1 << b)];
			if (d[i][j]) continue;
			for (auto a : v[i]) {
				if (j & (1 << a.second)) {
					d[i][j] = d[i][j] | d[a.first - 1][j ^ (1 << a.second)];
				}
			}
		}
	}

	for (int j = 0; j < (1 << k); j++)
		if (d[ptr][j]) {
			cout << "DA";
			return 0;
		}

	cout << "NE";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 24568 KB Output is correct
2 Correct 851 ms 25756 KB Output is correct
3 Correct 19 ms 23936 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 24 ms 24960 KB Output is correct
6 Incorrect 18 ms 23936 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 750 ms 25464 KB Output is correct
2 Correct 720 ms 25500 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 722 ms 25464 KB Output is correct
6 Incorrect 20 ms 25088 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 748 ms 25464 KB Output is correct
2 Correct 732 ms 25544 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 20 ms 23808 KB Output is correct
5 Incorrect 19 ms 24576 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 24824 KB Output is correct
2 Correct 875 ms 26096 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 18 ms 24448 KB Output is correct
6 Incorrect 18 ms 23936 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 625 ms 25208 KB Output is correct
2 Correct 708 ms 25372 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Incorrect 20 ms 24832 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 795 ms 25600 KB Output is correct
2 Correct 688 ms 25464 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Incorrect 19 ms 24960 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 25468 KB Output is correct
2 Correct 723 ms 25660 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 20 ms 23808 KB Output is correct
5 Incorrect 685 ms 25256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 24568 KB Output is correct
2 Correct 809 ms 25592 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Incorrect 19 ms 24448 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 24440 KB Output is correct
2 Correct 831 ms 25976 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 18 ms 24448 KB Output is correct
6 Correct 20 ms 24704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 24568 KB Output is correct
2 Correct 862 ms 25720 KB Output is correct
3 Correct 18 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Incorrect 301 ms 24696 KB Output isn't correct
6 Halted 0 ms 0 KB -