| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 
 | #include<cmath>#include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<algorithm>
 using namespace std;
 #define sqz main
 #define ll long long
 #define rep(i, a, b) for (int i = (a); i <= (b); i++)
 #define per(i, a, b) for (int i = (a); i >= (b); i--)
 #define Rep(i, a, b) for (int i = (a); i < (b); i++)
 #define travel(i, u) for (int i = head[u]; ~i; i = edge[i].next)
 
 const ll INF = 1e9, Mo = 51061;
 const int N = 100000;
 const double eps = 1e-6;
 namespace slow_IO
 {
 ll read()
 {
 ll x = 0; int zf = 1; char ch = getchar();
 while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
 if (ch == '-') zf = -1, ch = getchar();
 while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
 return x * zf;
 }
 void write(ll y)
 {
 if (y < 0) putchar('-'), y = -y;
 if (y > 9) write(y / 10);
 putchar(y % 10 + '0');
 }
 }
 using namespace slow_IO;
 
 int n = 0;
 int L[N + 5], R[N + 5], F[N + 5][2], G[N + 5][2];
 void dfs()
 {
 int point = ++n;
 char ch = getchar();
 if (ch == '0') return;
 if (ch == '1')
 {
 L[point] = n + 1;
 dfs();
 }
 else
 {
 L[point] = n + 1;
 dfs();
 R[point] = n + 1;
 dfs();
 }
 }
 
 void DP(int u)
 {
 if (!u) return;
 DP(L[u]), DP(R[u]);
 F[u][1] = F[L[u]][0] + F[R[u]][0] + 1;
 F[u][0] = max(F[L[u]][1] + F[R[u]][0], F[L[u]][0] + F[R[u]][1]);
 G[u][1] = G[L[u]][0] + G[R[u]][0] + 1;
 G[u][0] = min(G[L[u]][1] + G[R[u]][0], G[L[u]][0] + G[R[u]][1]);
 }
 
 int sqz()
 {
 dfs();
 DP(1);
 printf("%d %d\n", max(F[1][1], F[1][0]), min(G[1][1], G[1][0]));
 return 0;
 }
 
 |