# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
948852 | TrendBattles | Burza (COCI16_burza) | C++14 | 46 ms | 3676 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//https://oj.uz/problem/view/COCI16_burza
#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
#define INFILE "burza.inp"
#define OUTFILE "burza.out"
int main() {
ios::sync_with_stdio(0); cin.tie(0);
if (fopen(INFILE, "r")) {
freopen(INFILE, "r", stdin);
freopen(OUTFILE, "w", stdout);
}
int n, k; cin >> n >> k;
if (k * k >= n) {
cout << "DA\n"; return 0;
}
vector <vector <int>> graph(n + 1);
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
vector <int> leaves_L(n + 1, -1), leaves_R(n + 1, -1), depth(n + 1), parent(n + 1);
int vir_l = 0;
auto DFS = [&] (auto DFS, int u) {
if (depth[u] == k) {
leaves_L[u] = ++vir_l;
leaves_R[u] = vir_l;
return;
}
leaves_L[u] = vir_l;
for (int v : graph[u]) {
if (v == parent[u]) continue;
parent[v] = u;
depth[v] = depth[u] + 1;
DFS(DFS, v);
}
leaves_R[u] = vir_l;
};
DFS(DFS, 1);
vector <vector <int>> list_leaves(vir_l + 5);
for (int i = 2; i <= n; ++i) {
if (leaves_L[i] == -1) continue;
list_leaves[leaves_L[i]].push_back(i);
}
//for (int i = 1; i <= n; ++i) cerr << leaves_L[i] << ' ' << leaves_R[i] << '\n';
const int limit = ((1 << (k + 1)) >> 6) + 5;
vector <vector <lli>> dp(vir_l + 5, vector <lli> (limit));
dp[0][0] = 1;
for (int T = 0; T < vir_l; ++T) {
for (int mask_block = 0; mask_block < limit; ++mask_block) {
for (lli x = dp[T][mask_block]; x; x -= x & -x) {
int mask = (mask_block << 6) | __builtin_ctzll(x);
//cerr << "DEBUG: "<< T << ' ' << mask << '\n';
for (int nxt : list_leaves[T]) {
if (mask >> depth[nxt] & 1) continue;
//cerr << "NXT: " << nxt << '\n';
int nxt_mask = mask | (1 << depth[nxt]);
dp[leaves_R[nxt]][nxt_mask >> 6] |= 1LL << (nxt_mask & 63);
}
}
}
}
int exist = false;
for (int i = 0; i < limit; ++i) {
if (dp[vir_l][i]) {
exist = true; break;
}
}
cout << (exist ? "DA" : "NE");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |