提交 92a7af43 编写于 作者: qq_36480062's avatar qq_36480062

c

上级 24bcc576
......@@ -46,6 +46,7 @@ import java.util.Scanner;
* 先看她有木有对象,没有就在一起,有了就去和她男友商量,让他换个对象,
* 把女友让给自己;如果对方男友换了对象,这时就可以和该妹纸在一起了,
* 要是对方男友不肯让,就只好尝试再去考虑其他喜欢的女生了。
* 洛谷ac
*/
public class 匈牙利算法 {
public static void main(String[] args) {
......@@ -56,7 +57,6 @@ public class 匈牙利算法 {
for (int i = 0; i < m; i++) {
add(sc.nextInt(), sc.nextInt());
}
Arrays.fill(match, -1);
for (int i = 1; i <= n1; i++) {
Arrays.fill(vis, false);
if (find(i)) res++;
......@@ -73,12 +73,11 @@ public class 匈牙利算法 {
static int res = 0;
static boolean find(int v) {
vis[v] = true;
for (int i = he[v]; i != 0; i = ne[i]) {
int u = e[i];
if (!vis[u]) {
vis[u] = true;
if (match[u] == -1 || find(match[u])) {
if (match[u] == 0 || find(match[u])) {
match[u] = v;
return true;
}
......@@ -87,10 +86,10 @@ public class 匈牙利算法 {
return false;
}
static int[] match = new int[100006];
static boolean[] vis = new boolean[100006];
static int[] match = new int[10006];
static boolean[] vis = new boolean[10006];
static int n, m, cnt = 1;
static int[] e = new int[200005];
static int[] he = new int[100005];
static int[] ne = new int[200005];
static int[] e = new int[20005];
static int[] he = new int[10005];
static int[] ne = new int[20005];
}
......@@ -4,25 +4,59 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;
/**
*
* 洛谷ac,最快的
*/
public class 洛谷二分图最大匹配 {
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
n = nextInt();
m = nextInt();
t = nextInt();
int a, b, ans = 0;
while (t-- != 0) {
a = nextInt();
b = nextInt();
g[a].add(b);
}
for (int i = 1; i <= n; i++) {
if (dfs(i, i)) ans++;
}
System.out.println(ans);
}
private static boolean dfs(int u, int tag) {
if (st[u] == tag) return false;
st[u] = tag;
for (Integer w : g[u]) {
if (match[w] == 0 || dfs(match[w], tag)) {
match[w] = u;
return true;
}
}
return false;
}
static int n, m, N = 1010, M = 50000, t = 0;
static TreeSet<Integer>[] g = new TreeSet[N];
static int[] match = new int[N];
static int[] st = new int[N];
static {
for (int i = 0; i < g.length; i++) {
g[i] = new TreeSet<Integer>();
}
}
static int n, m, N = 510, M = 5000;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer("");
static StringTokenizer stt = new StringTokenizer("");
static String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
while (!stt.hasMoreTokens()) {
stt = new StringTokenizer(br.readLine());
}
return st.nextToken();
return stt.nextToken();
}
static int nextInt() throws IOException {
......
package 斜率;
/**
* 300
* https://www.acwing.com/problem/content/302/
* https://www.acwing.com/solution/content/13391/
*/
public class 任务安排 {
public static void main(String[] args) {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册