forked from spectre900/Binary-Image-Segmentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaling.cpp
67 lines (61 loc) · 1.34 KB
/
scaling.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
#include "graph.h"
using namespace std;
class Scaling : public Graph
{
public:
int dfs(int u, int cutoff, int flow = INT_MAX)
{
if (u == sink)
{
return flow;
}
done[u] = true;
for (pair<int, int> edge : adjList[u])
{
int v = edge.first;
int w = edge.second;
if (!done[v] and w >= cutoff)
{
int curFlow = dfs(v, cutoff, min(flow, w));
if (curFlow)
{
adjList[u][v] -= curFlow;
adjList[v][u] += curFlow;
return curFlow;
}
}
}
return 0;
}
int findMaxFlow()
{
int cutoff = 1000;
while (cutoff)
{
int flow = dfs(source, cutoff);
if (flow)
{
maxFlow += flow;
done = vector<bool>(V, false);
}
else
{
cutoff /= 2;
}
}
return maxFlow;
}
};
int main()
{
Scaling s = Scaling();
s.readInput();
clock_t start, end;
start = clock();
s.findMaxFlow();
s.findForeGround();
end = clock();
double duration = double(end - start) / double(CLOCKS_PER_SEC);
cout << duration;
}