Submission #144047

# Submission time Handle Problem Language Result Execution time Memory
144047 2019-08-15T20:51:02 Z Sorting Burza (COCI16_burza) C++14
0 / 160
2 ms 380 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 407;

int n, k;
vector<int> adj[MAXN], g[MAXN];

bool dfs(int u, int d, int p = -1){
	bool ok = false;

	for(int to: adj[u]){
		if(to == p){
			continue;
		}
		bool curr = dfs(to, d + 1, u);

		if(curr){
			g[u].push_back(to);
			ok = curr;
		}
	}
	if(d == k){
		ok = true;
	}

	return ok;
}

bool solve(const vector<int> &ver, int d){
	if(ver.size() > (k - d + 1)){
		return false;
	}
	if(ver.size() <= 1){
		return true;
	}

	for(int v: ver){
		vector<int> ver2;
		for(int u: ver){
			if(u == v){
				continue;
			}

			for(int to: g[u]){
				ver2.push_back(to);
			}

			if(solve(ver2, d + 1)){
				return true;
			}
		}
	}

	return false;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> k;

	for(int i = 0; i < n - 1; i++){
		int u, v;

		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1, 0);

	vector<int> ver = g[1];
	bool ans = solve(ver, 1);

	if(ans){
		cout << "DA\n";
	}
	else{
		cout << "NE\n";
	}

	return 0;
}

Compilation message

burza.cpp: In function 'bool solve(const std::vector<int>&, int)':
burza.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(ver.size() > (k - d + 1)){
     ~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -