FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp/data-structures/binaryTreeMinTimeBurn.cpp at master · AllAlgorithms/cpp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
AllAlgorithms
/
cpp
Public archive
Notifications
You must be signed in to change notification settings
Fork
340
Star
841
Code
Issues
9
Pull requests
33
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp
/
data-structures
/
binaryTreeMinTimeBurn.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (54 loc) · 1.35 KB
Breadcrumbs
cpp
/
data-structures
/
binaryTreeMinTimeBurn.cpp
Copy path
File metadata and controls
61 lines (54 loc) · 1.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
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
#
include
<
iostream
>
using
namespace
std
;
class
Node
{
public:
int
data;
Node *left, *right;
Node
(
int
x){
this
->
data
= x;
this
->
left
=
this
->
right
=
NULL
;
}
};
pair<
int
,
int
>
minTime
(Node* node,
int
*result){
if
(node->
left
==
NULL
&& node->
right
==
NULL
)
return
{
0
,
1
};
cout <<
"
Node
"
<< node->
data
<< endl;
pair<
int
,
int
> ansl={
0
,-
1
},ansr={
0
,-
1
};
if
(node->
left
)
ansl =
minTime
(node->
left
,result);
if
(node->
right
)
ansr =
minTime
(node->
right
,result);
if
(ansl.
second
== -
1
)
return
{ansr.
first
+
1
,ansr.
second
+
1
};
if
(ansr.
second
== -
1
)
return
{ansl.
first
+
1
,ansl.
second
+
1
};
if
(ansl.
first
<ansr.
first
){
if
(*result<ansl.
first
+
1
+ansr.
second
)
*result = ansl.
first
+
1
+ansr.
second
;
return
{ansl.
first
+
1
, ansr.
second
+
1
};
}
else
{
if
(*result<ansr.
first
+
1
+ansl.
second
)
*result = ansr.
first
+
1
+ansl.
second
;
return
{ansr.
first
+
1
, ansl.
second
+
1
};
}
}
int
main
()
{
Node *root =
new
Node
(
0
);
root->
left
=
new
Node
(
1
);
root->
right
=
new
Node
(
2
);
root->
left
->
left
=
new
Node
(
3
);
root->
left
->
right
=
new
Node
(
4
);
root->
right
->
left
=
new
Node
(
5
);
root->
right
->
right
=
new
Node
(
6
);
root->
left
->
left
->
left
=
new
Node
(
10
);
root->
left
->
right
->
left
=
new
Node
(
9
);
root->
right
->
right
->
left
=
new
Node
(
7
);
root->
right
->
right
->
right
=
new
Node
(
8
);
cout <<
"
Exec Start
"
<< endl;
int
*result =
new
int
;
minTime
(root,result);
cout << *result << endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL