# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1087342 | 2024-09-12T13:55:45 Z | Zero_OP | Burza (COCI16_burza) | C++14 | 34 ms | 1056 KB |
#include<bits/stdc++.h> using namespace std; #define sz(v) (int)v.size() #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define dbg(v) "[" #v " = " << (v) << "]" #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define rep(i, l, r) for(int i = (l); i < (r); ++i) using ll = long long; using vi = vector<int>; using vl = vector<long long>; using ld = long double; template<typename T> bool minimize(T& a, const T& b){ if(a > b){ return a = b, true; } return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b){ return a = b, true; } return false; } template<int dimension, typename T> struct tensor : public vector<tensor<dimension - 1, T>> { static_assert(dimension > 0, "Dimension must be positive !\n"); template<typename... Args> tensor(int n = 0, Args... args) : vector<tensor<dimension - 1, T>> (n, tensor<dimension - 1, T>(args...)) {} }; template<typename T> struct tensor<1, T> : public vector<T> { tensor(int n = 0, T val = T()) : vector<T>(n, val) {} }; const int MAX = 405; int n, k, tin[MAX], tout[MAX], depth[MAX], numLeaves; vector<int> adj[MAX]; bitset<1 << 20> dp[MAX]; vector<int> jumpList[MAX]; void dfs(int u, int pre){ if(depth[u] == k){ tin[u] = numLeaves++; tout[u] = numLeaves; } else{ tin[u] = numLeaves; for(int v : adj[u]) if(v != pre){ depth[v] = depth[u] + 1; dfs(v, u); } tout[u] = numLeaves; } //node u contain the leaves from [tin[u], tout[u]) if(u != 1) jumpList[tin[u]].push_back(u); } void testcase(){ cin >> n >> k; for(int i = 1; i < n; ++i){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } if(k * k >= n){ cout << "DA\n"; return; } depth[1] = 0; dfs(1, -1); if(numLeaves == 0){ cout << "DA\n"; return; } dp[0][0] = true; for(int i = 0; i < numLeaves; ++i){ for(int mask = 0; mask < (1 << k); ++mask){ if(!dp[i][mask]) continue; for(int u : jumpList[i]){ if(mask >> (depth[u] - 1) & 1) continue; dp[tout[u]][mask | (1 << (depth[u] - 1))] = true; } } } for(int mask = 0; mask < (1 << k); ++mask){ if(dp[numLeaves][mask]){ cout << "DA\n"; return; } } cout << "NE\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); file("task"); int T = 1; // cin >> T; while(T--){ testcase(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 604 KB | Output is correct |
2 | Correct | 22 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 864 KB | Output is correct |
2 | Correct | 21 ms | 812 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 34 ms | 992 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 856 KB | Output is correct |
2 | Correct | 23 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 604 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 640 KB | Output is correct |
2 | Correct | 30 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 860 KB | Output is correct |
2 | Correct | 25 ms | 868 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 604 KB | Output is correct |
6 | Correct | 0 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 792 KB | Output is correct |
2 | Correct | 26 ms | 888 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 612 KB | Output is correct |
6 | Correct | 0 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 912 KB | Output is correct |
2 | Correct | 28 ms | 852 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 34 ms | 1056 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 628 KB | Output is correct |
2 | Correct | 26 ms | 936 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 600 KB | Output is correct |
2 | Correct | 33 ms | 776 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 600 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 604 KB | Output is correct |
2 | Correct | 31 ms | 860 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 12 ms | 780 KB | Output is correct |
6 | Correct | 0 ms | 604 KB | Output is correct |