# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
398211 |
2021-05-04T00:23:17 Z |
Mwhdi |
Burza (COCI16_burza) |
C++14 |
|
2 ms |
336 KB |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define F first
#define S second
const int maxn = 4e2+10;
int n, k, H[maxn], MAX_H[maxn], cost[maxn], dad[maxn];
set <int> G[maxn];
bool visited[maxn], ANS[maxn];
void dfs (int v , int h) {
visited[v] = 1;
H[v] = h;
if (H[v] == k) {
ANS[v] = 1;
}
MAX_H[v] = h;
for (int i : G[v]) {
if (!visited[i]) {
dad[i] = v;
dfs (i , h+1);
MAX_H[v] = max (MAX_H[v] , MAX_H[i]);
}
}
}
void solve (int v) {
//cout << v;
visited[v] = 1;
if (ANS[v]) {
return ;
}
for (int i : G[v]) {
if (!visited[i]) {
solve (i);
}
}
//cout << v << "*";
set <int> vertices, nei;
vertices.insert (v);
for (int t = 1; t <= k - H[v]; t++) {
for (int vertex : vertices) {
for (int i : G[vertex]) {
if (i != dad[vertex]) {
nei.insert (i);
//cout << i << ' ' << v;
}
}
}
//cout << v << "*";
vertices.clear ();
for (int i : nei) {
vertices.insert (i);
}
nei.clear ();
//cout << v << "*";
int MAX_cost = -1, erase_v = 0;
for (int i : vertices) {
if (cost[i] > MAX_cost) {
MAX_cost = cost[i];
erase_v = i;
}
}
//cout << erase_v << "*";
/*if (v == 1) {
cout << erase_v << '\t';
for (int i : vertices) {
cout << i << "!";
}
cout << '\n';
}*/
vertices.erase (vertices.find(erase_v));
/*if (v == 1) {
cout << erase_v << '\t';
for (int i : vertices) {
cout << i << "!";
}
cout << '\n';
}*/
if (!vertices.size()) {
cost[v] = t;
return ;
}
//cout << v << "*";
}
if (vertices.size()) {
cost[v] = 1e9;
}
ANS[v] = 1;
}
int main () {
/*ios::sync_with_stdio(false);
cin.tie(0);*/
cin >> n >> k;
for (int i = 1; i <= n-1; i++) {
int u, v; cin >> u >> v;
G[u].insert (v);
G[v].insert (u);
}
dfs (1 , 0);
//
bool ans = 1;
for (int i = 1; i <= n; i++) {
if (MAX_H[i] < k || H[i] > k) {
for (int j = 1; j <= n; j++) {
if (G[j].find (i) != G[j].end()) {
G[j].erase (G[j].find (i));
}
}
}
else {
ans = 0;
}
}
if (ans) {
cout << "DA";
return 0;
}
for (int i = 1; i <= n; i++) {
visited[i] = 0;
}
solve (1);
//cout << "*";
if (cost[1] == 1e9) {
cout << "NE";
}
else {
cout << "DA";
}
//cout << cost[1] << ' ' << cost[2] << ' ' << cost[3] << ' ' << cost[4] << ' ' << cost[5];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |