public void Solve() { var n = sc.Integer(); var g = sc.Integer(); var E = sc.Integer(); var p = sc.Integer(g); var G = new MaxFlow(n + 1); for (int i = 0; i < E; i++) { var a = sc.Integer(); var b = sc.Integer(); G.AddUndirectedEdge(a, b, 1); } foreach (var q in p) { G.AddDirectedEdge(q, n, 1); } var cost = G.GetMaxFlow(0, n); IO.Printer.Out.WriteLine(cost); }
private static void Go() { var n = RI(); var m = RI(); var x = new List <Item>(); var p = new List <Item>(); var extraX = new List <Item>(); var extraP = new List <Item>(); for (int i = 0; i < m; i++) { var newItem = new Item(); newItem.Tp = ReadAnyOf(new char[] { 'x', '+', 'o' }); newItem.X = RI() - 1; newItem.Y = RI() - 1; if (newItem.Tp == 'x' || newItem.Tp == 'o') { x.Add(newItem); } if (newItem.Tp == '+' || newItem.Tp == 'o') { p.Add(newItem); } } var xx = Enumerable.Range(0, n).Except(x.Select(xxx => xxx.X)).ToList(); var yy = Enumerable.Range(0, n).Except(x.Select(xxx => xxx.Y)).ToList(); for (int i = 0; i < xx.Count; i++) { extraX.Add(new Item() { X = xx[i], Y = yy[i], Tp = 'x' }); } // 0 - root // 1 - N+N-1 > D1 // N+N - N+N+N+N-1 > D // 4N > exist. var d1 = new bool[n + n - 1]; // x+y var d2 = new bool[n + n - 1]; // x-y+n-1 foreach (var t in p) { d1[t.X + t.Y] = true; d2[t.X - t.Y + n - 1] = true; } var nn = 4 * n + 1; var map = new int[nn, nn]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!d1[i + j] && !d2[i - j + n - 1]) { var d1Id = i + j; var d2Id = i - j + n - 1; var v1 = 1 + d1Id; var v2 = n + n + d2Id; map[0, v1] = 1; map[v1, v2] = 1; map[v2, nn - 1] = 1; } } } var flow = new MaxFlow(map, nn); var maxFlow = flow.GetMaxFlow(0, nn - 1); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!d1[i + j] && !d2[i - j + n - 1]) { var d1Id = i + j; var d2Id = i - j + n - 1; var v1 = 1 + d1Id; var v2 = n + n + d2Id; if (map[v1, v2] == 0) { extraP.Add(new Item() { X = i, Y = j, Tp = '+' }); } } } } var q1 = new char[n, n]; foreach (var t in x) { q1[t.X, t.Y] = t.Tp; } foreach (var t in p) { q1[t.X, t.Y] = t.Tp; } var q2 = (char[, ])(q1.Clone()); foreach (var t in extraX) { if (q2[t.X, t.Y] == '+') { t.Tp = 'o'; } q2[t.X, t.Y] = t.Tp; } foreach (var t in extraP) { if (q2[t.X, t.Y] == 'x') { t.Tp = 'o'; } q2[t.X, t.Y] = t.Tp; } var result = new List <Item>(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (q1[i, j] != q2[i, j]) { result.Add(new Item() { X = i, Y = j, Tp = q2[i, j] }); } } } var sb = new StringBuilder(); var max = x.Count + p.Count + extraX.Count + extraP.Count; sb.Append(max + " " + result.Count); foreach (var t in result) { sb.AppendLine(); sb.Append(t.ToString()); } SetAnswer(sb.ToString()); }