Submission #2213226
Source Code Expand
#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<<endl #define smax(x,y) (x)=max((x),(y)) #define smin(x,y) (x)=min((x),(y)) #define MEM(x,y) memset((x),(y),sizeof (x)) #define sz(x) (int)(x).size() #define RT return #define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d)) #define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e)) using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; const int INF = 100005; int N; vi G[100005]; vi va[100005]; int bin(vi &a, int r, int lim) { auto g = [&](int mid) { int i = 0, j = r - 1; for (int k = 0; k < r / 2;) { if (i == mid) i++; else if (j == mid)j--; else { k++; if (a[i++] + a[j--] > lim) { RT 0; } } } RT 1; }; if (!g(r - 1))RT - 1; int ok = r - 1, ng = -1; while (ok - ng > 1) { int mid = (ok + ng) / 2; (g(mid) ? ok : ng) = mid; } RT ok; } int f(int u, int p, int lim) { int C = sz(G[u]) - 1; auto &a = va[u]; if (sz(a) < C) { a.reserve(C); a.resize(C); } for (int i = 0, j = 0; i < sz(G[u]); ++i) { int v = G[u][i]; if (v != p) { a[j++] = f(v, u, lim); } } sort(all(a)); if (sz(a) && a.back() > lim)RT INF; if (C % 2) { rep(i, C / 2) if (a[i] + a[C - 2 - i] > lim)RT INF; int k = bin(a, C, lim); if (k == -1)RT INF; RT a[k] + 1; } else { int chk = 1; rep(i, C / 2) { if (a[i] + a[C - 1 - i] > lim) { chk = 0; break; } } if (chk)RT 1; int k = bin(a, C - 1, lim); if (k == -1)RT INF; RT a[k] + 1; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); cin >> N; rep(i, N - 1) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } int A = 0; rep(i, N + 1)A += sz(G[i]) & 1; A /= 2; G[1].push_back(0); int ng = 0, ok = N; while (ok - ng > 1) { int mid = (ng + ok) / 2; int re = f(1, 0, mid); (re - 1 <= mid ? ok : ng) = mid; } int B = ok; cout << A << ' ' << B << endl; f(1, 0, 4); }
Submission Info
Submission Time | |
---|---|
Task | F - Christmas Tree |
User | paruki |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2781 Byte |
Status | WA |
Exec Time | 199 ms |
Memory | 20480 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 900 | ||||||
Status |
|
|
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 | 144 ms | 9984 KB |
02.txt | AC | 153 ms | 9984 KB |
03.txt | AC | 150 ms | 9984 KB |
04.txt | AC | 149 ms | 9984 KB |
05.txt | WA | 185 ms | 19072 KB |
06.txt | WA | 186 ms | 20480 KB |
07.txt | AC | 171 ms | 13184 KB |
08.txt | AC | 175 ms | 15104 KB |
09.txt | AC | 172 ms | 13824 KB |
10.txt | AC | 174 ms | 15488 KB |
11.txt | AC | 99 ms | 8960 KB |
12.txt | AC | 98 ms | 8960 KB |
13.txt | AC | 99 ms | 8960 KB |
14.txt | AC | 99 ms | 8960 KB |
15.txt | AC | 148 ms | 9984 KB |
16.txt | AC | 144 ms | 9856 KB |
17.txt | AC | 154 ms | 10368 KB |
18.txt | AC | 160 ms | 10752 KB |
19.txt | AC | 153 ms | 11136 KB |
20.txt | AC | 158 ms | 11264 KB |
21.txt | AC | 162 ms | 11520 KB |
22.txt | AC | 173 ms | 12288 KB |
23.txt | WA | 191 ms | 18944 KB |
24.txt | AC | 195 ms | 18304 KB |
25.txt | AC | 148 ms | 9984 KB |
26.txt | AC | 138 ms | 9856 KB |
27.txt | AC | 153 ms | 10368 KB |
28.txt | AC | 155 ms | 10752 KB |
29.txt | AC | 158 ms | 11008 KB |
30.txt | AC | 164 ms | 11264 KB |
31.txt | AC | 170 ms | 11648 KB |
32.txt | AC | 197 ms | 12544 KB |
33.txt | WA | 199 ms | 18688 KB |
34.txt | WA | 188 ms | 17536 KB |
35.txt | AC | 147 ms | 9856 KB |
36.txt | AC | 121 ms | 9472 KB |
37.txt | AC | 147 ms | 9856 KB |
38.txt | AC | 155 ms | 10496 KB |
39.txt | AC | 151 ms | 10880 KB |
40.txt | AC | 155 ms | 11264 KB |
41.txt | AC | 170 ms | 11520 KB |
42.txt | AC | 181 ms | 12672 KB |
43.txt | WA | 180 ms | 15616 KB |
44.txt | WA | 189 ms | 15360 KB |
45.txt | AC | 147 ms | 9856 KB |
46.txt | AC | 144 ms | 9984 KB |
47.txt | AC | 147 ms | 9984 KB |
48.txt | AC | 156 ms | 10496 KB |
49.txt | AC | 151 ms | 10880 KB |
50.txt | AC | 162 ms | 11264 KB |
51.txt | AC | 167 ms | 11520 KB |
52.txt | AC | 172 ms | 12032 KB |
53.txt | AC | 189 ms | 14464 KB |
54.txt | AC | 190 ms | 17024 KB |
55.txt | AC | 87 ms | 8824 KB |
56.txt | AC | 106 ms | 8824 KB |
57.txt | AC | 105 ms | 8824 KB |
58.txt | AC | 107 ms | 8824 KB |
59.txt | AC | 139 ms | 11648 KB |
60.txt | AC | 139 ms | 11008 KB |
61.txt | AC | 140 ms | 11264 KB |
62.txt | AC | 141 ms | 11648 KB |
63.txt | AC | 139 ms | 12160 KB |
64.txt | WA | 138 ms | 14588 KB |
65.txt | AC | 124 ms | 13304 KB |
66.txt | WA | 165 ms | 14204 KB |
67.txt | AC | 3 ms | 4992 KB |
68.txt | AC | 3 ms | 4992 KB |
69.txt | AC | 3 ms | 4992 KB |
70.txt | AC | 3 ms | 4992 KB |
71.txt | AC | 3 ms | 4992 KB |
72.txt | AC | 3 ms | 4992 KB |
s1.txt | AC | 3 ms | 4992 KB |
s2.txt | AC | 3 ms | 4992 KB |
s3.txt | AC | 3 ms | 4992 KB |