AtCoder Grand Contest 009

Submission #4022844

Source codeソースコード

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 100050
int head[N],to[N<<1],nxt[N<<1],cnt,n,tmp[22],f[22][N],ans;
inline void add(int u,int v) {
	to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
void merge(int *a,int *b) {
	int i;
	for(i=0;i<=20;i++) a[i]+=b[i];
void dfs(int x,int y) {
	int i;
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) dfs(to[i],x);
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) merge(tmp,f[to[i]]);
	int k=0;
	for(i=20;i>=0;i--) {
		if(tmp[i]>1) {
			k=i+1; break;
	for(;tmp[k];k++) ;
int main() {
	int i,x,y;
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1,0); printf("%d\n",ans);


Task問題 D - Uninity
User nameユーザ名 ibuki_suika
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 RE
Score得点 0
Source lengthソースコード長 849 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:35:56: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);

Test case


Set name Score得点 / Max score Cases
Sample - s1.txt,s2.txt
All 0 / 1400 01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt,20.txt,21.txt,22.txt,23.txt,24.txt,25.txt,26.txt,27.txt,28.txt,29.txt,30.txt,31.txt,32.txt,33.txt,34.txt,35.txt,36.txt,37.txt,38.txt,39.txt,40.txt,41.txt,42.txt,43.txt,44.txt,45.txt,46.txt,47.txt,48.txt,49.txt,50.txt,51.txt,52.txt,53.txt,54.txt,55.txt,56.txt,57.txt,58.txt,59.txt,60.txt,61.txt,62.txt,63.txt,64.txt,65.txt,66.txt,67.txt,68.txt,69.txt,70.txt,71.txt,72.txt,s1.txt,s2.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01.txt RE
02.txt RE
03.txt RE
04.txt RE
05.txt RE
06.txt RE
07.txt RE
08.txt RE
09.txt RE
10.txt RE
11.txt RE
12.txt RE
13.txt RE
14.txt RE
15.txt RE
16.txt RE
17.txt RE
18.txt RE
19.txt RE
20.txt RE
21.txt RE
22.txt RE
23.txt RE
24.txt RE
25.txt RE
26.txt RE
27.txt RE
28.txt RE
29.txt RE
30.txt RE
31.txt RE
32.txt RE
33.txt RE
34.txt RE
35.txt RE
36.txt RE
37.txt RE
38.txt RE
39.txt RE
40.txt RE
41.txt RE
42.txt RE
43.txt RE
44.txt RE
45.txt RE
46.txt RE
47.txt RE
48.txt RE
49.txt RE
50.txt RE
51.txt RE
52.txt RE
53.txt RE
54.txt RE
55.txt RE
56.txt RE
57.txt RE
58.txt RE
59.txt RE
60.txt RE
61.txt RE
62.txt RE
63.txt AC 2 ms 6272 KB
64.txt AC 1 ms 2176 KB
65.txt AC 2 ms 4224 KB
66.txt AC 2 ms 4224 KB
67.txt AC 2 ms 4224 KB
68.txt AC 2 ms 4224 KB
69.txt AC 2 ms 4224 KB
70.txt AC 1 ms 2176 KB
71.txt AC 1 ms 2176 KB
72.txt AC 2 ms 4224 KB
s1.txt AC 2 ms 4224 KB
s2.txt AC 2 ms 6272 KB