Submission #1986081


Source Code Expand

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define ele int
using namespace std;
#define maxn 200010
const ele INF=1e9;
struct edge{
	ele v;
	edge *nxt;
}ep[maxn<<1],*ecnt;
ele n,r,d[maxn],f[maxn];
edge *h[maxn];
inline void addedge(ele u,ele v){
	edge *p=ecnt++;
	p->v=v; p->nxt=h[u];
	h[u]=p;
}
void dfs(ele p,ele i,ele B){
	vector<ele> lst;
	for (edge *j=h[i]; j; j=j->nxt)
		if (j->v!=p){
			dfs(i,j->v,B);
			lst.push_back(f[j->v]);
		}
	if (lst.size()%2==0) lst.push_back(0);
	sort(lst.begin(),lst.end());
	f[i]=INF;
	for (int r=0; r<lst.size(); ++r){
		ele u=0,v=lst.size()-1;
		bool flag=true;
		while (u<v){
			if (u==r) ++u;
			if (v==r) --v;
			if (u<v && lst[u]+lst[v]>B){ flag=false; break; }
			++u; --v;
		}
		if (flag){ f[i]=lst[r]+1; break; }
	}
}
inline bool test(ele B){
	dfs(-1,r,B);
	return f[r]<=B+1;
}
int main(){
	scanf("%d",&n);
	ecnt=ep; memset(h,0,sizeof(h)); memset(d,0,sizeof(d));
	for (int i=0; i<n-1; ++i){
		ele x,y;
		scanf("%d%d",&x,&y); --x,--y;
		addedge(x,y); addedge(y,x);
		++d[x]; ++d[y];
	}
	ele cnt=0;
	for (int i=0; i<n; ++i)
		if (d[i]&1) ++cnt,r=i;
	ele L=0,R=n-1;
	while (R-L>1){
		ele mid=(L+R)>>1;
		if (test(mid)) R=mid; else L=mid;
	}
	printf("%d %d\n",cnt/2,R);
	return 0;
}

Submission Info

Submission Time
Task F - Christmas Tree
User eleele
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1321 Byte
Status AC
Exec Time 273 ms
Memory 17664 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:47:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:51:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y); --x,--y;
                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 75
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 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, s3.txt
Case Name Status Exec Time Memory
01.txt AC 201 ms 8320 KB
02.txt AC 211 ms 8320 KB
03.txt AC 211 ms 8320 KB
04.txt AC 211 ms 8320 KB
05.txt AC 178 ms 17664 KB
06.txt AC 178 ms 17664 KB
07.txt AC 225 ms 12800 KB
08.txt AC 216 ms 10880 KB
09.txt AC 273 ms 11520 KB
10.txt AC 225 ms 12160 KB
11.txt AC 146 ms 8668 KB
12.txt AC 140 ms 8608 KB
13.txt AC 143 ms 8592 KB
14.txt AC 140 ms 8556 KB
15.txt AC 208 ms 8320 KB
16.txt AC 234 ms 8320 KB
17.txt AC 216 ms 8320 KB
18.txt AC 190 ms 8448 KB
19.txt AC 164 ms 8448 KB
20.txt AC 174 ms 8448 KB
21.txt AC 164 ms 8576 KB
22.txt AC 172 ms 9600 KB
23.txt AC 175 ms 12928 KB
24.txt AC 168 ms 14976 KB
25.txt AC 208 ms 8320 KB
26.txt AC 202 ms 8320 KB
27.txt AC 200 ms 8320 KB
28.txt AC 182 ms 8320 KB
29.txt AC 178 ms 8448 KB
30.txt AC 172 ms 8448 KB
31.txt AC 173 ms 8576 KB
32.txt AC 175 ms 9600 KB
33.txt AC 169 ms 15616 KB
34.txt AC 179 ms 16128 KB
35.txt AC 209 ms 8320 KB
36.txt AC 220 ms 8320 KB
37.txt AC 215 ms 8320 KB
38.txt AC 195 ms 8320 KB
39.txt AC 169 ms 8448 KB
40.txt AC 164 ms 8448 KB
41.txt AC 172 ms 8576 KB
42.txt AC 174 ms 9216 KB
43.txt AC 167 ms 11264 KB
44.txt AC 166 ms 12544 KB
45.txt AC 209 ms 8320 KB
46.txt AC 198 ms 8320 KB
47.txt AC 218 ms 8320 KB
48.txt AC 196 ms 8320 KB
49.txt AC 169 ms 8448 KB
50.txt AC 173 ms 8448 KB
51.txt AC 172 ms 8576 KB
52.txt AC 165 ms 9216 KB
53.txt AC 179 ms 12160 KB
54.txt AC 176 ms 14336 KB
55.txt AC 136 ms 9292 KB
56.txt AC 138 ms 9292 KB
57.txt AC 137 ms 9292 KB
58.txt AC 137 ms 9292 KB
59.txt AC 199 ms 11136 KB
60.txt AC 209 ms 10880 KB
61.txt AC 198 ms 11776 KB
62.txt AC 199 ms 12032 KB
63.txt AC 220 ms 11776 KB
64.txt AC 164 ms 13520 KB
65.txt AC 151 ms 12280 KB
66.txt AC 160 ms 15024 KB
67.txt AC 2 ms 3840 KB
68.txt AC 2 ms 3840 KB
69.txt AC 2 ms 3840 KB
70.txt AC 2 ms 3840 KB
71.txt AC 2 ms 3840 KB
72.txt AC 2 ms 3840 KB
s1.txt AC 2 ms 3840 KB
s2.txt AC 2 ms 3840 KB
s3.txt AC 2 ms 3840 KB