Submission #581659

# Submission time Handle Problem Language Result Execution time Memory
581659 2022-06-23T01:42:53 Z BackNoob Burza (COCI16_burza) C++14
0 / 160
1000 ms 23892 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
 
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
 
int n;
int k;
int depth[mxN];
vector<int> adj[mxN];
vector<int> node[mxN];
bool ok = true;
bool ban[mxN];
 
void dfs(int u, int par)
{
	for(int v : adj[u]) {
		if(v == par) continue;
		depth[v] = depth[u] + 1;
		dfs(v, u);
	}
}

void getans(int u, int par)
{
	if(depth[u] == k) ok = false;
	for(int v : adj[u]) {
		if(v == par || ban[v] == true) continue;
		getans(v, u);
	}
}

void gen(int x)
{
	if(sz(node[x]) == 0) {
		ok = true;
		getans(1, -1);
		if(ok == true) {
			cout << "DA" << endl;
			exit(0);
		}
		return;
	}
	for(auto it : node[x]) {
		ban[it] = true;
		gen(x + 1);
		ban[it] = false;
	}
}


void solve()
{
	cin >> n >> k;
	for(int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs(1, -1);
	for(int i = 1; i <= n; i++) node[depth[i]].pb(i);
	gen(1);
	cout << "NE";
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(TASK".inp" , "r" , stdin);
    //freopen(TASK".out" , "w" , stdout);
 
    int tc = 1;
    //cin >> tc;
    while(tc--) {
    	solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 23824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 23892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 23764 KB Time limit exceeded
2 Halted 0 ms 0 KB -