From 92a7af43e254506d71254e355baa170b29161e9c Mon Sep 17 00:00:00 2001 From: Departuers <2644631299@qq.com> Date: Fri, 21 Aug 2020 17:33:51 +0800 Subject: [PATCH] c --- ...\345\210\251\347\256\227\346\263\225.java" | 15 +++--- ...\345\244\247\345\214\271\351\205\215.java" | 48 ++++++++++++++++--- ...\345\212\241\345\256\211\346\216\222.java" | 12 +++++ 3 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 "ACWing/src/\346\226\234\347\216\207/\344\273\273\345\212\241\345\256\211\346\216\222.java" diff --git "a/ACWing/src/graph/\345\214\210\347\211\231\345\210\251\347\256\227\346\263\225.java" "b/ACWing/src/graph/\345\214\210\347\211\231\345\210\251\347\256\227\346\263\225.java" index a0d7d6a..7977d86 100644 --- "a/ACWing/src/graph/\345\214\210\347\211\231\345\210\251\347\256\227\346\263\225.java" +++ "b/ACWing/src/graph/\345\214\210\347\211\231\345\210\251\347\256\227\346\263\225.java" @@ -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]; } diff --git "a/ACWing/src/graph/\346\264\233\350\260\267\344\272\214\345\210\206\345\233\276\346\234\200\345\244\247\345\214\271\351\205\215.java" "b/ACWing/src/graph/\346\264\233\350\260\267\344\272\214\345\210\206\345\233\276\346\234\200\345\244\247\345\214\271\351\205\215.java" index 966930f..bf95a64 100644 --- "a/ACWing/src/graph/\346\264\233\350\260\267\344\272\214\345\210\206\345\233\276\346\234\200\345\244\247\345\214\271\351\205\215.java" +++ "b/ACWing/src/graph/\346\264\233\350\260\267\344\272\214\345\210\206\345\233\276\346\234\200\345\244\247\345\214\271\351\205\215.java" @@ -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[] 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(); + } } - 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 { diff --git "a/ACWing/src/\346\226\234\347\216\207/\344\273\273\345\212\241\345\256\211\346\216\222.java" "b/ACWing/src/\346\226\234\347\216\207/\344\273\273\345\212\241\345\256\211\346\216\222.java" new file mode 100644 index 0000000..8e94aa9 --- /dev/null +++ "b/ACWing/src/\346\226\234\347\216\207/\344\273\273\345\212\241\345\256\211\346\216\222.java" @@ -0,0 +1,12 @@ +package 斜率; + +/** + * 300 + * https://www.acwing.com/problem/content/302/ + * https://www.acwing.com/solution/content/13391/ + */ +public class 任务安排 { + public static void main(String[] args) { + + } +} -- GitLab