Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pdp-camp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Public
pdp-camp
Commits
f28da6ee
Commit
f28da6ee
authored
May 09, 2017
by
Panagiotis Kostopanagiotis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SPOJ - QUEST4, Max Bipartite Matching
parent
2dadbc50
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
quest4.cpp
2017/quest4.cpp
+68
-0
No files found.
2017/quest4.cpp
0 → 100644
View file @
f28da6ee
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define MAXN 250
using
namespace
std
;
int
visited
[
MAXN
+
1
],
par
[
MAXN
+
1
],
flow
[
MAXN
+
1
][
MAXN
+
1
],
cap
[
MAXN
+
1
][
MAXN
+
1
];
bool
bfs
(
int
s
,
int
t
)
{
memset
(
par
,
0
,
sizeof
(
par
)
);
memset
(
visited
,
0
,
sizeof
(
visited
)
);
queue
<
int
>
Q
;
Q
.
push
(
s
);
visited
[
s
]
=
true
;
par
[
s
]
=
-
1
;
while
(
!
Q
.
empty
()
)
{
int
u
=
Q
.
front
();
Q
.
pop
();
for
(
int
i
=
0
;
i
<
MAXN
;
i
++
)
{
if
(
!
visited
[
i
]
&&
cap
[
u
][
i
]
-
flow
[
u
][
i
]
>
0
)
{
visited
[
i
]
=
true
;
par
[
i
]
=
u
;
Q
.
push
(
i
);
}
}
}
return
visited
[
t
];
}
int
maxflow
(
int
s
,
int
t
)
{
int
ans
=
0
;
while
(
bfs
(
s
,
t
)
)
{
int
aug
=
2500000
;
for
(
int
i
=
t
;
i
!=
s
;
i
=
par
[
i
]
)
{
aug
=
min
(
aug
,
cap
[
par
[
i
]
][
i
]
-
flow
[
par
[
i
]
][
i
]
);
}
ans
+=
aug
;
for
(
int
i
=
t
;
i
!=
s
;
i
=
par
[
i
]
)
{
flow
[
par
[
i
]
][
i
]
+=
aug
;
flow
[
i
][
par
[
i
]
]
-=
aug
;
}
}
return
ans
;
}
int
main
(
void
)
{
int
T
;
scanf
(
"%d"
,
&
T
);
while
(
T
--
)
{
int
N
,
x
,
y
;
scanf
(
"%d"
,
&
N
);
for
(
int
i
=
1
;
i
<=
N
;
i
++
)
{
scanf
(
"%d%d"
,
&
x
,
&
y
);
cap
[
x
][
y
+
120
]
=
1
;
}
for
(
int
i
=
0
;
i
<
120
;
i
++
)
{
cap
[
240
][
i
]
=
1
;
cap
[
i
+
120
][
241
]
=
1
;
}
printf
(
"%d
\n
"
,
maxflow
(
240
,
241
)
);
memset
(
flow
,
0
,
sizeof
(
flow
)
);
memset
(
cap
,
0
,
sizeof
(
cap
)
);
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment