-
Notifications
You must be signed in to change notification settings - Fork 0
/
acicl.c
executable file
·72 lines (67 loc) · 1.11 KB
/
acicl.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
//#include "sort.c"
#include <stdio.h>
#include <stdlib.h>
#define N 5
struct NODE
{
//0 nero
//1 grigio
//2 bianco
int C;
int K;
};
int aciclic(int EDGES[N][N], struct NODE* NODES[])
{
int i;
for(i = 0; i < N; i++)
return DFV(i, EDGES, NODES);
}
int DFV(int S, int EDGES[N][N], struct NODE* NODES[])
{
int i,R;
NODES[S]->C = 1;
for(i = 0; i < N; i++)
{
if(EDGES[S][i])
{
if(NODES[i]->C == 2)
{
R = DFV(i,EDGES,NODES);
if(!R) return 0;
}
else
{
if(NODES[i]->C == 1) return 0;
}
}
}
NODES[S]->C = 0;
return 1;
}
int main()
{
struct NODE* N1 = malloc(sizeof(struct NODE));
struct NODE* N2 = malloc(sizeof(struct NODE));
struct NODE* N3 = malloc(sizeof(struct NODE));
struct NODE* N4 = malloc(sizeof(struct NODE));
struct NODE* N5 = malloc(sizeof(struct NODE));
N1->C = 2;
N1->K = 1;
N2->C = 2;
N2->K = 2;
N3->C = 2;
N3->K = 3;
N4->C = 2;
N4->K = 4;
N5->C = 2;
N5->K = 5;
struct NODE* NODES[] = {N1,N2,N3,N4,N5};
int graph[N][N] =
{{0,1,0,0,0},
{0,0,1,0,1},
{0,0,0,1,0},
{0,0,0,0,0},
{1,0,0,0,0}};
printf("RIS: %d\n",DFV(0,graph,NODES));
return 0;
}