-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.c
84 lines (74 loc) · 1.24 KB
/
D.c
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
#include<stdio.h>
#include<stdlib.h>
int main(){
int n,m;
scanf("%d %d",&n,&m);
int adjacencyMatrix[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
adjacencyMatrix[i][j]=0;
}
}
int x,y;
for(int i=0;i<m;i++){
scanf("%d %d",&x,&y);
adjacencyMatrix[x-1][y-1]=1;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d",adjacencyMatrix[i][j]);
}
printf("\n");
}
int reflexive=1;
for(int i=0;i<n;i++){
if(adjacencyMatrix[i][i]==0){
reflexive = 0;
break;
}
}
int symmetric = 1;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(adjacencyMatrix[i][j]!=adjacencyMatrix[j][i]){
symmetric=0;
break;
}
}
}
int transitive = 1;
for(int i=0;i<n;i++){
int flag2 = 0;
for(int j=0;j<n;j++){
int flag1 = 0;
for(int k=0;k<n;k++){
if(adjacencyMatrix[i][j]==1 && adjacencyMatrix[j][k]==1){
if(adjacencyMatrix[i][k]!=1){
transitive=0;
flag1 =1;
break;
}
}
}
if(flag1==1){
flag2 = 1;
break;
}
}
if(flag2==1){
break;
}
}
if(reflexive==1){
printf("reflexive \n");
}
if(symmetric==1){
printf("symmetric \n");
}
if(transitive==1){
printf("transitive \n");
}
if(reflexive==0 && symmetric==0 && transitive==0){
printf("-1");
}
}