Submission #7619272


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class FordFulkerson
{
    class Edge {
	public int to, cap, rev;
	public Edge(int _to, int _cap, int _rev)
	{
	    to = _to; cap = _cap; rev = _rev;
	}
    }

    List<Edge>[] G;
    bool[] used;
    int MAX_V;

    public void AddEdge(int from, int to, int cap)
    {
	G[from].Add(new Edge(to, cap, G[to].Count));
	G[to].Add(new Edge(from, 0, G[from].Count - 1));
    }
    
    int dfs (int v, int t, int f)
    {
	if (v == t) return f;
	used[v] = true;
	for (int i = 0; i < G[v].Count; i++)
	{
	    Edge e = G[v][i];
	    if (!used[e.to] && e.cap > 0)
	    {
		int d = dfs(e.to, t, Math.Min(f, e.cap));
		if (d > 0)
		{
		    e.cap -= d;
		    G[e.to][e.rev].cap += d;
		    return d;
		}
	    }
	}
	return 0;
    }

    public int MaxFlow(int s, int t)
    {
	int flow = 0;
	for (int i = 0; i < MAX_V; i++)
	    used = false;
	
	while (true)
	{
	    int f = dfs(s, t, 1000000000);
	    if (f == 0) return flow;
	    flow += f;
	}
    }

    public FordFulkerson(int maxv)
    {
	MAX_V = maxv;
	G = new List<Edge>[MAX_V];
	for (int i = 0; i < MAX_V; i++)
	    G[i] = new List<Edge>();

	used = new bool[MAX_V];
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int n = tmp[0], g = tmp[1], e = tmp[2];

	int[] marked = ReadIntArray();

	var mf = new FordFulkerson(n+1);

	for (int i = 0; i < e; i++)
	{
	    tmp = ReadIntArray();
	    int a = tmp[0], b = tmp[1];
	    mf.AddEdge(a, b, 1);
	    mf.AddEdge(b, a, 1);
	}

	foreach (int x in marked)
	{
	    mf.AddEdge(x, n, 1);
	}

	WriteLine(mf.MaxFlow(0, n));
    }
}

Submission Info

Submission Time
Task D - 浮気予防
User unnohideyuki
Language C# (Mono 4.6.2.0)
Score 0
Code Size 1956 Byte
Status CE

Compile Error

./Main.cs(61,13): error CS0029: Cannot implicitly convert type `bool' to `bool[]'