Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
competitive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruno Freitas Tissei
competitive
Commits
f6e37529
Commit
f6e37529
authored
5 years ago
by
Bruno Freitas Tissei
Browse files
Options
Downloads
Patches
Plain Diff
Small fixes and improvements
Signed-off-by:
Bruno Freitas Tissei
<
bft15@inf.ufpr.br
>
parent
ef4d3297
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
algorithms/graph/hld.cpp
+2
-2
2 additions, 2 deletions
algorithms/graph/hld.cpp
algorithms/graph/lca.cpp
+7
-9
7 additions, 9 deletions
algorithms/graph/lca.cpp
with
9 additions
and
11 deletions
algorithms/graph/hld.cpp
+
2
−
2
View file @
f6e37529
...
...
@@ -88,14 +88,14 @@ struct HLD {
for
(;
head
[
a
]
!=
head
[
b
];
b
=
par
[
head
[
b
]])
{
if
(
dep
[
head
[
a
]]
>
dep
[
head
[
b
]])
swap
(
a
,
b
);
ans
=
seg
.
op
(
ans
,
seg
.
query
(
pos
[
head
[
b
]],
pos
[
b
]));
ans
=
seg
.
func
(
ans
,
seg
.
query
(
pos
[
head
[
b
]],
pos
[
b
]));
}
if
(
dep
[
a
]
>
dep
[
b
])
swap
(
a
,
b
);
// Remove "+ 1" when values are associated with vertices
return
seg
.
op
(
ans
,
seg
.
query
(
pos
[
a
]
+
1
,
pos
[
b
]));
return
seg
.
func
(
ans
,
seg
.
query
(
pos
[
a
]
+
1
,
pos
[
b
]));
}
// Updates value of i-th edge (or vertice)
...
...
This diff is collapsed.
Click to expand it.
algorithms/graph/lca.cpp
+
7
−
9
View file @
f6e37529
...
...
@@ -22,10 +22,12 @@
vector
<
ii
>
graph
[
MAX
];
int
par
[
MAX
][
LOG
],
cost
[
MAX
][
LOG
];
template
<
class
F
=
function
<
T
(
const
T
&
,
const
&
T
)>
>
struct
LCA
{
F
func
;
vector
<
int
>
h
;
LCA
(
int
N
)
:
h
(
N
)
LCA
(
int
N
,
F
&
func
)
:
h
(
N
),
func
(
func
)
{
init
();
}
void
init
()
{
...
...
@@ -34,10 +36,6 @@ struct LCA {
dfs
(
0
);
// root is 0
}
int
op
(
int
a
,
int
b
)
{
return
a
+
b
;
// or max(a, b)
}
void
dfs
(
int
v
,
int
p
=
-
1
,
int
c
=
0
)
{
par
[
v
][
0
]
=
p
;
cost
[
v
][
0
]
=
c
;
...
...
@@ -48,7 +46,7 @@ struct LCA {
for
(
int
i
=
1
;
i
<
LOG
;
++
i
)
if
(
par
[
v
][
i
-
1
]
!=
-
1
)
{
par
[
v
][
i
]
=
par
[
par
[
v
][
i
-
1
]][
i
-
1
];
cost
[
v
][
i
]
=
op
(
cost
[
v
][
i
],
op
(
cost
[
v
][
i
-
1
],
cost
[
v
][
i
]
=
func
(
cost
[
v
][
i
],
func
(
cost
[
v
][
i
-
1
],
cost
[
par
[
v
][
i
-
1
]][
i
-
1
]));
}
...
...
@@ -65,7 +63,7 @@ struct LCA {
for
(
int
i
=
LOG
-
1
;
i
>=
0
;
--
i
)
if
(
par
[
a
][
i
]
!=
-
1
&&
h
[
par
[
a
][
i
]]
>=
h
[
b
])
{
ans
=
op
(
ans
,
cost
[
a
][
i
]);
ans
=
func
(
ans
,
cost
[
a
][
i
]);
a
=
par
[
a
][
i
];
}
...
...
@@ -79,7 +77,7 @@ struct LCA {
for
(
int
i
=
LOG
-
1
;
i
>=
0
;
--
i
)
if
(
par
[
a
][
i
]
!=
-
1
&&
par
[
a
][
i
]
!=
par
[
b
][
i
])
{
ans
=
op
(
ans
,
op
(
cost
[
a
][
i
],
cost
[
b
][
i
]));
ans
=
func
(
ans
,
func
(
cost
[
a
][
i
],
cost
[
b
][
i
]));
a
=
par
[
a
][
i
];
b
=
par
[
b
][
i
];
}
...
...
@@ -88,7 +86,7 @@ struct LCA {
if
(
a
==
b
)
return
ans
;
else
return
op
(
ans
,
op
(
cost
[
a
][
0
],
cost
[
b
][
0
]));
return
func
(
ans
,
func
(
cost
[
a
][
0
],
cost
[
b
][
0
]));
#else
return
par
[
a
][
0
];
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment