-
Notifications
You must be signed in to change notification settings - Fork 2
/
transitibeClosure.cpp
50 lines (46 loc) · 1.02 KB
/
transitibeClosure.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
#include <bitset>
#include <iostream>
#include <vector>
void getInput (
std::vector < std::bitset < 1000 > > &graph,
) {
int n;
std::cin >> n;
std::string data;
for (int i = 0; i < n; ++i) {
std::cin >> data;
graph.emplace_back(data);
}
}
void floydAlgorithm (
std::vector < std::bitset < 1000 > > &graph
) {
int n = graph.size();
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
if (graph[i].test(k)) {
graph[i] |= graph[n - 1 - k];
}
}
}
}
void setOutput (
std::vector < std::bitset < 1000 > > &graph
) {
int n = graph.size();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
std::cout << graph[i][n - j - 1];
}
std::cout << std::endl;
}
}
int main() {
std::vector < std::bitset <1000> > graph;
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
getInput(graph, n);
floydAlgorithm(graph);
setOutput(graph);
return 0;
}