-
Notifications
You must be signed in to change notification settings - Fork 1
/
roy_warshall.cpp
122 lines (102 loc) · 1.54 KB
/
roy_warshall.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <fstream>
using namespace std;
int a[100][100], n, m, p[100][100];
ifstream f("rw.in");
void citire(){
int x, y;
for(int i=0; i<m; i++){
f>>x>>y;
a[x][y] = a[y][x] = 1;
p[x][y] = p[y][x] = x;
}
}
void rw(){
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
if(i != k){
for(int j=1; j<=n; j++){
if(j != k && a[i][j] == 0 && j != i){
a[i][j] = a[i][k] * a[k][j];
}
}
}
}
}
}
void rw_recon_drum(){
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
if(i != k){
for(int j=1; j<=n; j++){
if(j != k && a[i][j] == 0 && j != i){
a[i][j] = a[i][k] * a[k][j];
p[i][j] = k;
}
}
}
}
}
}
int conex(){
for(int i=1; i<n; i++){
for(int j=i+1; j<=n; j++){
if(a[i][j] == 0){
return 0;
}
}
}
return 1;
}
void tip(){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cout<<a[i][j]<<' ';
}
cout<<"\n";
}
}
void tip_p(){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cout<<p[i][j]<<' ';
}
cout<<"\n";
}
}
void tip_lant(int x, int y){
if(p[y][x] != 0){
tip_lant(x, p[y][x]);
cout<<y<<' ';
}
else{
cout<<x<<' ';
}
}
void ciclii(){
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
if(i != k){
for(int j=1; j<=n; j++){
if(j != k && a[i][j] == 0){
a[i][j] = a[i][k] * a[k][j];
}
}
}
}
}
}
int main(){
f>>n>>m;
citire();
//tip();
//rw();
//rw_recon_drum();
ciclii();
cout<<"\n";
tip();
//tip_p();
cout<<"\n";
//tip_lant(1, 4);
//cout<<"\nconex: "<<conex();
}