8000 Update 2250 · dongju97/basic-algo-lecture@502d223 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit 502d223

Browse files
committed
Update 2250
1 parent 7b9feea commit 502d223

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

0x19/solutions/2250.cpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : heheHwang
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/d6c7ee9ea1a64b95885c8858ddbf1404
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
7+
const int MXN = 10010;
8+
int lc[MXN], rc[MXN], N, colno, root;
9+
pair<int, int> depth[MXN];
10+
void inorder(int curr, int d) {
11+
if (curr == -1) return;
12+
inorder(lc[curr], d + 1);
13+
colno++;
14+
if (!depth[d].first || colno < depth[d].first)
15+
depth[d].first = colno;
16+
if (!depth[d].second || depth[d].second < colno)
17+
depth[d].second = colno;
18+
inorder(rc[curr], d + 1);
19+
}
20+
int main(void) {
821
ios::sync_with_stdio(0);
922
cin.tie(0);
10-
23+
24+
cin >> N;
25+
vector<bool> isRoot(N + 1, true);
26+
for (int i = 0; i < N; i++) {
27+
int p, l, r;
28+
cin >> p >> l >> r;
29+
lc[p] = l;
30+
rc[p] = r;
31+
32+
if (l != -1) isRoot[l] = false;
33+
if (r != -1) isRoot[r] = false;
34+
}
35+
for (int i = 1; i <= N; i++)
36+
if (isRoot[i]) {
37+
root = i;
38+
break;
39+
}
40+
int mxWidth = 0, mxDepth = 0;
41+
inorder(root, 0);
42+
for (int d = 0; d < N; d++) {
43+
auto [l, r] = depth[d];
44+
if (l + r == 0) break;
45+
int width = r - l + 1;
46+
if (mxWidth < width) {
47+
mxWidth = width;
48+
mxDepth = d;
49+
}
50+
}
51+
cout << mxDepth + 1 << ' ' << mxWidth;
1152
}

0 commit comments

Comments
 (0)
0