Skip to content

Commit c45875b

Browse files
committed
Update solved P & README.md
1 parent 9c221cf commit c45875b

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Problem-Solving List
22

33

4+
### 2020/09/11 일반 알고리즘
5+
* 1번 : [BOJ 18224](https://www.acmicpc.net/problem/18224) **미로에 갇힌 건우**
6+
* 2번 : [BOJ 19542](https://www.acmicpc.net/problem/19542) **전단지 돌리기**
7+
* 3번 : [BOJ 1595](https://www.acmicpc.net/problem/1595) **북쪽나라의 도로**
8+
9+
*****************************************************************************
10+
411
### 2020/09/09 일반 알고리즘
512
* 1번 : [BOJ 2263](https://www.acmicpc.net/problem/2263) **트리의 순회**
613
* 2번 : [BOJ 2250](https://www.acmicpc.net/problem/2250) **트리와 높이와 너비**

‎TnJ/20200909/BOJ_2250.cpp‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// <트리의 높이와 너비> - BOJ_2250
2+
// 트리의 (h,w) 찾기, 중위순회
3+
4+
#include<bits/stdc++.h>
5+
using namespace std;
6+
7+
int tree[10001][2]{}, rt, N;
8+
bool vi[10001]{};
9+
int ans[10001][2]{};
10+
11+
int C=1, mdpt=0;
12+
void inO(int node, int dpt) {
13+
if(node == -1) return;
14+
inO(tree[node][0], dpt+1);
15+
ans[dpt][0] = min(ans[dpt][0], C);
16+
ans[dpt][1] = max(ans[dpt][1], C);
17+
C+=1;
18+
mdpt = max(mdpt, dpt);
19+
inO(tree[node][1], dpt+1);
20+
}
21+
22+
int main() {
23+
ios_base::sync_with_stdio(0);
24+
cin.tie(0);
25+
cin>>N;
26+
int n,l,r;
27+
for(int i=1; i<=N; i++){
28+
cin>>n>>l>>r;
29+
tree[n][0] = l;
30+
tree[n][1] = r;
31+
if(l!=-1) vi[l] = true;
32+
if(r!=-1) vi[r] = true;
33+
ans[i][0] = 1e9;
34+
}
35+
for(int i=1; i<=N; i++) if(!vi[i]) {rt = i; break;}
36+
37+
inO(rt,1);
38+
39+
int max_=0, maxi=1;
40+
for(int k=1; k<=mdpt; k++){
41+
int t = ans[k][1]-ans[k][0]+1;
42+
if(max_ < t) {
43+
max_ = t;
44+
maxi = k;
45+
}
46+
}
47+
cout<<maxi<<' '<<max_;
48+
}

0 commit comments

Comments
 (0)