Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ README languages: [Japanese](README.ja.md)

### ac-library-csharp

[AtCoder Library](https://github.com/atcoder/ac-library/) の C# 移植です。
[AtCoder Library](https://github.com/atcoder/ac-library/tree/v1.3) の C# 移植です。

### AtCoderAnalyzer

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ README languages: [Japanese](README.ja.md)

### ac-library-csharp

C# port of [AtCoder Library](https://github.com/atcoder/ac-library/)
C# port of [AtCoder Library](https://github.com/atcoder/ac-library/tree/v1.3)

### AtCoderAnalyzer

Expand Down
54 changes: 54 additions & 0 deletions Source/AtCoderLibrary/Graph/Internal/CSR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.ComponentModel;

namespace AtCoder.Internal
{
/// <summary>
/// 有向グラフの辺集合を表します。
/// </summary>
/// <example>
/// <code>
/// for (int i = graph.Starts[v]; i &gt; graph.Starts[v + 1]; i++)
/// {
/// int to = graph.Edges[i];
/// }
/// </code>
/// </example>
[EditorBrowsable(EditorBrowsableState.Never)]
public class CSR<TEdge>
{
/// <summary>
/// 各頂点から伸びる有向辺数の累積和を取得します。
/// </summary>
public readonly int[] Start;

/// <summary>
/// 有向辺の終点の配列を取得します。
/// </summary>
public readonly TEdge[] EList;

public CSR(int n, List<(int from, TEdge e)> edges)
{
// 本家 C++ 版 ACL を参考に実装。通常の隣接リストと比較して高速か否かは未検証。
Start = new int[n + 1];
EList = new TEdge[edges.Count];

foreach (var (from, _) in edges)
{
Start[from + 1]++;
}

for (int i = 1; i <= n; i++)
{
Start[i] += Start[i - 1];
}

var counter = (int[])Start.Clone();
foreach (var (from, e) in edges)
{
EList[counter[from]++] = e;
}
}
}

}
13 changes: 5 additions & 8 deletions Source/AtCoderLibrary/Graph/MaxFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ TValue Dfs(int v, TValue up)
_g[v][iter[v]].Cap = op.Add(_g[v][iter[v]].Cap, d);
_g[e.To][e.Rev].Cap = op.Subtract(_g[e.To][e.Rev].Cap, d);
res = op.Add(res, d);
if (res.Equals(up)) break;
if (res.Equals(up)) return res;
}

level[v] = _n;
return res;
}

Expand All @@ -283,12 +283,9 @@ TValue Dfs(int v, TValue up)
{
iter[i] = 0;
}
while (op.LessThan(flow, flowLimit))
{
var f = Dfs(t, op.Subtract(flowLimit, flow));
if (op.Equals(f, default)) break;
flow = op.Add(flow, f);
}
var f = Dfs(t, op.Subtract(flowLimit, flow));
if (op.Equals(f, default)) break;
flow = op.Add(flow, f);
}
return flow;
}
Expand Down
Loading