競プロ典型 90 問 026
種別: 記事
カテゴリ: 競技プログラミング
サブカテゴリ: AtCoder > 競プロ典型 90 問
タグ: #解いた問題
(工事中)
AtCoder で公開されている競プロ典型 90 問 の026 を解いた
解き方
解答例
下は上記の方法で解いたときの提出結果である。また、その提出の際に提出したソースコードをその下に転記する。
code: C
#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 = ev-1;
if (visitedv-1 > 0) {
return;
}
visitedv-1 = 1;
depthv-1 = d;
count_altd%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 *e100000 = {};
list pool200000 = {};
int used = 0;
int visited100000 = {};
int depth100000 = {};
int count_alt2 = {};
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);
poolused.op = b;
poolused.next = ea-1;
ea-1 = pool+used;
used++;
poolused.op = a;
poolused.next = eb-1;
eb-1 = pool+used;
used++;
}
func(1, 1, e, visited, depth, count_alt);
if (count_alt0 < count_alt1) {
alt = 1;
}
for(int i = 0; i < n; i++) {
if (depthi % 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;
}
私の提出一覧
table: submissions_atcoder_typical90_026
提出のURL 提出時刻 結果 備考
1回目 https://atcoder.jp/contests/typical90/submissions/22350591 2021-05-06T21:21:10+0900 WA
2回目 https://atcoder.jp/contests/typical90/submissions/22350913 2021-05-06T21:33:51+0900 AC
感想
ローカルにおいてあったzakkan.txt(雑感)には、まだ書かれていないので、こっちに直接書く
この問題に関してもはっきり覚えてはいないが、隣り合わないということは「深さ」で分ければ良いかなというのは暫く考えたら気づいた気もする。
あとは$ \frac{N}{2} にできるかどうかが微妙に悩んだかも?