Submission #537971

# Submission time Handle Problem Language Result Execution time Memory
537971 2022-03-16T01:15:21 Z Pietra Burza (COCI16_burza) C++14
160 / 160
217 ms 208228 KB
#include<bits/stdc++.h>
using namespace std ; 

const int maxn = 405 ; 

int n, tin[maxn], tout[maxn], timer, k, nivel[maxn], dp[(1<<20)][maxn] ; 
vector<int> grafo[maxn], vec[maxn] ; 

void dfs(int v, int p){ 

	if(nivel[v] >= 0) vec[nivel[v]].push_back(v) ;

	tin[v] = timer + 1 ; 

	for(auto a : grafo[v]){
		if(a == p) continue ; 
		nivel[a] = nivel[v] + 1 ; 
		if(nivel[a] < k) dfs(a, v) ;  
	}

	if(nivel[v] == k-1) timer++ ;

	tout[v] = timer ; 

}

int main(){

	ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; 

	cin >> n >> k ; 

	for(int i = 1 ; i < n ; i++){
		int u, v ; 
		cin >> u >> v ; u--, v-- ; 
		grafo[u].push_back(v) ; grafo[v].push_back(u) ; 
	}

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

	nivel[0] = -1 ; 

	dfs(0, 0) ;  

	for(int i = 0 ; i < (1<<k) ; i++) dp[i][0] = 1 ; 

    for(int mask = 1 ; mask < (1<<k) ; mask++){

    	for(int i = 0 ; i < k ; i++){
    		
    		if(!(mask&(1<<i))) continue ; 

    		for(auto at : vec[i]){
    			if(dp[mask^(1<<i)][tin[at]-1]) dp[mask][tout[at]] = 1 ; 
    		}

    	}

    }

    for(int i = 0 ; i < (1<<k) ; i++){
    	if(dp[i][timer]){
    		cout << "DA\n" ; exit(0) ; 
    	}
    }

    cout << "NE\n" ; 

}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 26324 KB Output is correct
2 Correct 217 ms 208124 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 204 ms 208116 KB Output is correct
2 Correct 197 ms 208120 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 202 ms 208064 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 208116 KB Output is correct
2 Correct 208 ms 208028 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 52288 KB Output is correct
2 Correct 207 ms 208120 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 208140 KB Output is correct
2 Correct 209 ms 208100 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 208120 KB Output is correct
2 Correct 203 ms 208144 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 340 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 208120 KB Output is correct
2 Correct 201 ms 208120 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 206 ms 208228 KB Output is correct
6 Correct 1 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 52308 KB Output is correct
2 Correct 208 ms 208208 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 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 26324 KB Output is correct
2 Correct 209 ms 208204 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 104272 KB Output is correct
2 Correct 203 ms 208128 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 94 ms 104276 KB Output is correct
6 Correct 1 ms 352 KB Output is correct