-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgraph.h
79 lines (69 loc) · 1.56 KB
/
graph.h
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
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
class Graph
{
protected:
int V;
int E;
int sink;
int source;
int maxFlow;
vector<bool> done;
vector<unordered_map<int, int>> adjList;
public:
Graph()
{
freopen("data.txt", "r", stdin);
maxFlow = 0;
cin >> V >> E;
cin >> source >> sink;
done = vector<bool>(V, false);
adjList = vector<unordered_map<int, int>>(V);
}
void readInput()
{
for (int i = 0; i < E; i++)
{
int u, v, w;
cin >> u >> v >> w;
if (adjList[u].find(v) == adjList[u].end())
{
adjList[u][v] = 0;
}
adjList[u][v] += w;
if (adjList[v].find(u) == adjList[v].end())
{
adjList[v][u] = 0;
}
}
}
void findForeGround()
{
queue<int> q;
vector<int> visited(V, false);
q.push(source);
visited[source] = true;
while (!q.empty())
{
int u = q.front();
q.pop();
for (pair<int, int> p : adjList[u])
{
int v = p.first;
int w = p.second;
if (!visited[v] and w)
{
visited[v] = true;
q.push(v);
}
}
}
for (int i = 0; i < visited.size(); i++)
{
if (i != source && visited[i])
{
cout << i << " ";
}
}
}
};