提出 #22350913


ソースコード 拡げる

#include <stdio.h>

typedef struct list {
  int op;
  struct list *next;
} list;

void func(int v, int d, list **e, int *visited, int *depth, int *count_alt) {
  list *l = e[v-1];
  
  if (visited[v-1] > 0) {
    return;
  }
  
  visited[v-1] = 1;
  depth[v-1] = d;
  count_alt[d%2]++;
  
  while(l != NULL) {
    func(l->op, d+1, e, visited, depth, count_alt);
    l = l->next;
  }
  
  return;
}

int main () {
  int n = 0;
  
  int res = 0;
  
  list *e[100000] = {};
  list pool[200000] = {};
  int used = 0;
  
  int visited[100000] = {};
  int depth[100000] = {};
  int count_alt[2] = {};
  int print_count = 0;
  
  int alt = 0;
  
  res = scanf("%d", &n);
  
  for (int i = 0; i < n-1; i++) {
    int a = 0;
    int b = 0;
    
    res = scanf("%d", &a);
    res = scanf("%d", &b);
    
    pool[used].op = b;
    pool[used].next = e[a-1];
    e[a-1] = pool+used;
    used++;
    
    pool[used].op = a;
    pool[used].next = e[b-1];
    e[b-1] = pool+used;
    used++;
  }
  
  func(1, 1, e, visited, depth, count_alt);
  
  if (count_alt[0] < count_alt[1]) {
    alt = 1;
  }
  
  for(int i = 0; i < n; i++) {
    if (depth[i] % 2 == alt) {
      print_count++;
      if (print_count < n / 2) {
        printf("%d ", i+1);
      } else if (print_count == n / 2) {
        printf("%d\n", i+1);
      }
    }
  }
  
  return 0;
}

提出情報

提出日時
問題 026 - Independent Set on a Tree(★4)
ユーザ chro4896
言語 C (GCC 9.2.1)
得点 4
コード長 1417 Byte
結果 AC
実行時間 56 ms
メモリ 11436 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 4 / 4
結果
AC × 2
AC × 24
セット名 テストケース
Sample sample01.txt, sample02.txt
All corner01.txt, corner02.txt, max.txt, random00.txt, random01.txt, random02.txt, random03.txt, random04.txt, random05.txt, random06.txt, random07.txt, random08.txt, random09.txt, sample01.txt, sample02.txt, specific01.txt, specific02.txt, specific03.txt, specific04.txt, specific05.txt, specific06.txt, specific07.txt, specific08.txt, specific09.txt
ケース名 結果 実行時間 メモリ
corner01.txt AC 11 ms 6340 KiB
corner02.txt AC 7 ms 6396 KiB
max.txt AC 53 ms 6456 KiB
random00.txt AC 26 ms 6352 KiB
random01.txt AC 40 ms 6368 KiB
random02.txt AC 44 ms 6376 KiB
random03.txt AC 29 ms 6448 KiB
random04.txt AC 6 ms 6316 KiB
random05.txt AC 17 ms 6348 KiB
random06.txt AC 33 ms 6360 KiB
random07.txt AC 46 ms 6352 KiB
random08.txt AC 14 ms 6312 KiB
random09.txt AC 22 ms 6380 KiB
sample01.txt AC 11 ms 6400 KiB
sample02.txt AC 5 ms 6312 KiB
specific01.txt AC 56 ms 11436 KiB
specific02.txt AC 40 ms 6340 KiB
specific03.txt AC 45 ms 6388 KiB
specific04.txt AC 38 ms 6336 KiB
specific05.txt AC 43 ms 6388 KiB
specific06.txt AC 39 ms 6336 KiB
specific07.txt AC 39 ms 6332 KiB
specific08.txt AC 47 ms 10088 KiB
specific09.txt AC 46 ms 8812 KiB