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
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
17d387c8
Commit
17d387c8
authored
6 years ago
by
Bruno Freitas Tissei
Browse files
Options
Downloads
Patches
Plain Diff
Add Edmonds-Karp
Signed-off-by:
Bruno Freitas Tissei
<
bft15@inf.ufpr.br
>
parent
75269967
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
algorithms/graph/edmonds_karp.cpp
+66
-0
66 additions, 0 deletions
algorithms/graph/edmonds_karp.cpp
algorithms/graph/ford_fulkerson.cpp
+1
-1
1 addition, 1 deletion
algorithms/graph/ford_fulkerson.cpp
testing.py
+1
-0
1 addition, 0 deletions
testing.py
with
68 additions
and
1 deletion
algorithms/graph/edmonds_karp.cpp
0 → 100644
+
66
−
0
View file @
17d387c8
/**
* Edmonds-Karp
*
* Complexity (time): O(V*E^2)
* Complexity (space): O(V^2)
*/
int
N
;
int
par
[
MAX
];
int
graph
[
MAX
][
MAX
],
rg
[
MAX
][
MAX
];
bool
cont
[
MAX
];
// Finds if there's a path between s and t using non-full
// residual edges
bool
path
(
int
s
,
int
t
)
{
queue
<
int
>
Q
;
Q
.
push
(
s
);
cont
[
s
]
=
true
;
while
(
!
Q
.
empty
())
{
int
u
=
Q
.
front
();
Q
.
pop
();
if
(
u
==
t
)
return
true
;
for
(
int
i
=
0
;
i
<
N
;
++
i
)
if
(
!
cont
[
i
]
&&
rg
[
u
][
i
])
{
cont
[
i
]
=
true
;
par
[
i
]
=
u
;
Q
.
push
(
i
);
}
}
return
false
;
}
// Returns maximum flow between s (source) and t (sink)
int
edmonds_karp
(
int
s
,
int
t
)
{
int
ans
=
0
;
par
[
s
]
=
-
1
;
mset
(
cont
,
0
);
memcpy
(
rg
,
graph
,
sizeof
(
graph
));
// Repeat while there's a valid path between s and t
while
(
path
(
s
,
t
))
{
int
flow
=
inf
;
// Get the minimum capacity among all edges of the chosen path
for
(
int
i
=
t
;
par
[
i
]
!=
-
1
;
i
=
par
[
i
])
flow
=
min
(
f
,
rg
[
par
[
i
]][
i
]);
// Update residual graph
for
(
int
i
=
t
;
par
[
i
]
!=
-
1
;
i
=
par
[
i
])
{
rg
[
par
[
i
]][
i
]
-=
flow
;
rg
[
i
][
par
[
i
]]
+=
flow
;
}
ans
+=
flow
;
mset
(
cont
,
0
);
}
return
ans
;
}
This diff is collapsed.
Click to expand it.
algorithms/graph/ford_fulkerson.cpp
+
1
−
1
View file @
17d387c8
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* Ford-Fulkerson
* Ford-Fulkerson
*
*
* Complexity (time): O(Ef)
* Complexity (time): O(Ef)
* Complexity (space): O(V
+ E
)
* Complexity (space): O(V
^2
)
*/
*/
int
N
;
int
N
;
...
...
This diff is collapsed.
Click to expand it.
testing.py
+
1
−
0
View file @
17d387c8
...
@@ -32,6 +32,7 @@ def gen_code_latex(arr, depth):
...
@@ -32,6 +32,7 @@ def gen_code_latex(arr, depth):
for
i
in
arr
:
for
i
in
arr
:
print
(
'
\\
'
+
depth
+
'
{
'
+
i
+
'
}
'
)
print
(
'
\\
'
+
depth
+
'
{
'
+
i
+
'
}
'
)
def
gen_latex
(
tree
):
def
gen_latex
(
tree
):
stack
=
[
(
tree
,
0
)
]
stack
=
[
(
tree
,
0
)
]
depth
=
[
'
chapter
'
,
'
section
'
,
'
subsection
'
]
depth
=
[
'
chapter
'
,
'
section
'
,
'
subsection
'
]
...
...
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