# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
782366 | 2023-07-13T21:09:37 Z | vgoofficial | Burza (COCI16_burza) | C++14 | 1 ms | 340 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; int n,k; vector<vector<int>> edges; vector<int> depth; vector<int> parents; vector<vector<int>> depths(400); int maxDepth(int i, int dpth) { depth[i]=dpth; int maxD = dpth; for(int j = 0; j < edges[i].size(); j++) { int l = edges[i][j]; if(depth[l]!=-1) continue; if(dpth==k) { edges[i][j]=-1; } else { if(maxDepth(l, dpth+1)!=k) { edges[i][j]=-1; } else { parents[l]=i; maxD=k; } } } if(maxD==k) { depths[dpth].push_back(i); } return maxD; } bool dfs2(int level, vector<bool> unaccessible) { /* cout << "dfs2 called " << level << endl; for(int i = 0; i < n; i++) { cout << unaccessible[i] << " "; } cout << endl; */ int notDone = 0; for(int i: depths[level]) { //cout << i << " " << parents[i] << endl; if(unaccessible[parents[i]]) { unaccessible[i]=true; } else { notDone++; } } /* for(int i = 0; i < n; i++) { cout << unaccessible[i] << " "; } cout << endl; */ if(notDone<2) return true; if(level==k) return false; for(int i: depths[level]) { if(!unaccessible[i]) { unaccessible[i]=true; if(dfs2(level+1, unaccessible)) { return true; } unaccessible[i]=false; } } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; if(k^2>n) { cout << "DA" << endl; return 0; } edges=vector<vector<int>>(n); depth=vector<int>(n, -1); parents=vector<int>(n, -1); depth[0]=0; for(int i = 1; i < n; i++) { int a,b; cin >> a >> b; edges[a-1].push_back(b-1); edges[b-1].push_back(a-1); } maxDepth(0, 0); /* for(int i = 0; i < n; i++) { cout << i << " " << depth[i] << " " << parents[i] << endl; for(int j: depths[i]) { cout << j << " "; } cout << endl; for(int j: edges[i]) { cout << j << " "; } cout << endl; } */ if(dfs2(1, vector<bool>(n))) { cout << "DA" << endl; } else { cout << "NE" << endl; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |