이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define maxn 410
using namespace std;
vector<int> g[maxn];
int n, k, a, b, children[maxn], parent[maxn], mark[maxn], color[maxn], atual[maxn], prox[maxn], is_root[maxn], prox_count, deleted_node[maxn];
pair<int, int > vertice_para_cortar;
void rotate_tree(int father, int child){
parent[father] = child;
parent[child] = -1;
children[father] -= children[child];
children[child] += children[father];
}
void cut(int a){
deleted_node[a] = true;
if(prox[a] == 1) prox_count--;
prox[a] = 0;
}
// V é uma sugestão de raiz.
void centroid_component(int v){
mark[v] = true;
for(int i = 0; i < g[v].size(); i++){
int u = g[v][i];
int tam = children[u];
if(deleted_node[u]) continue;
if( tam > vertice_para_cortar.first && atual[v] ){
vertice_para_cortar = make_pair(tam, u);
}
if(!mark[u]){
rotate_tree(v, u);
centroid_component(u);
rotate_tree(u, v);
}
}
}
void make_root(int v, int _color){
children[v] = 1;
color[v] = _color;
for(int i = 0; i < g[v].size(); i++){
int u = g[v][i];
if(deleted_node[u]) continue;
if(parent[v] == u) continue;
if(atual[v]) prox[u] = 1;
parent[u] = v;
make_root(u, _color);
children[v] += children[u];
}
}
int next_step(int step){
vertice_para_cortar = make_pair(-1, -1);
memset(mark, 0, sizeof mark);
memset(is_root, 0, sizeof is_root);
for(int i = 1; i <= n; i++ ){
if( color[i] != step && !deleted_node[i] ){
make_root(i, step);
is_root[i] = 1;
}
}
for(int i = 1; i <= n; i++){
if( is_root[i] ) centroid_component(i);
}
if(vertice_para_cortar.first == -1) return 0;
cut(vertice_para_cortar.first);
if(prox_count == 0) return 0;
prox_count = 0;
for(int i = 1; i <= n; i++){
atual[i] = prox[i];
prox[i] = 0;
}
return 1;
}
int main(){
scanf(" %d %d", &n, &k);
for(int i = 0; i < n-1; i++){
scanf(" %d %d", &a, &b);
g[a].push_back(b);
g[b].push_back(a);
}
atual[1] = 1;
int p = 1;
while(next_step(p++));
if(p<=k) cout << "DA" << endl;
else cout << "NE" << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
burza.cpp: In function 'void centroid_component(int)':
burza.cpp:26:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < g[v].size(); i++){
~~^~~~~~~~~~~~~
burza.cpp: In function 'void make_root(int, int)':
burza.cpp:46:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < g[v].size(); i++){
~~^~~~~~~~~~~~~
burza.cpp: In function 'int main()':
burza.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~~
burza.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~
# | 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... |