답안 #84051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84051 2018-11-12T14:07:23 Z wjoao Burza (COCI16_burza) C++11
0 / 160
3 ms 688 KB
#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;
}

Compilation message

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);
     ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 688 KB Output isn't correct
2 Halted 0 ms 0 KB -