-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project2.cpp
146 lines (123 loc) · 3.14 KB
/
Project2.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*@@@@@@@@@@@@@@@@@@@@@@@ 2º PROJECTO ASA @@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
#include <cstdio>
#include <vector>
#include <list>
#include <stdlib.h>
#define UNDEFINED -1
#define NOVO_V 0
#define GRAY 1
#define BLACK 2
#define oo 1000000000
int *cor;
int *caminho;
int cabeca, cu;
int *Q;
typedef int Vertex;
class Edge{
public: Vertex destino;
public: bool fluxo;
public: Vertex getDestino(){ return destino;}
//public: void setDestino( int v){ destino= (Vertex) v;}
public: void setDestino( Vertex v){ destino=v;}
public: bool getFluxo(){ return fluxo;};
public: void setFluxo(bool f){ fluxo=f;};
};
class Graph{
public: std::vector< std::list<Edge> > _lists;
public: int _numVertex;
public: int _numConnections;
public: Graph(int numVertex,int numConnections){
int i;
_numVertex = numVertex;
_numConnections = numConnections;
for(i = 0; i < _numVertex;i++){
_lists.push_back( std::list<Edge>() );
}
}
public: std::list<Edge>::iterator getIterator(Vertex vertex){
return _lists[vertex-1].begin();
}
public: std::list<Edge>::iterator getIteratorEnd(Vertex vertex){
return _lists[vertex-1].end();
}
public: void addConnection(Vertex v1,Vertex v2){
Edge* manq=(Edge*) malloc(sizeof(Edge));
Edge* inho=(Edge*) malloc(sizeof(Edge));
manq->setDestino(v2);
manq->setFluxo(false);
inho->setDestino(v1);
inho->setFluxo(false);
_lists[v1].push_back(*manq);
_lists[v2].push_back(*inho);
}
public: int getVertexes(){
return _numVertex;
}
};
void push(int shit) {
Q[cu] = shit;
cu++;
cor[shit] = GRAY;
}
int pop() {
int x = Q[cabeca];
cabeca++;
cor[x] = BLACK;
return x;
}
int bfs(int start, int end, int n, Graph *garfo) {
int u, v;
printf("a");
for (u=0; u<n; u++) {
cor[u] = NOVO_V;
}
cabeca = cu = 0;
push(start);
printf("passou o ciclo de u");
caminho[start] = -1;
while (cabeca != cu) {
u = pop();
// Search all adjacent white nodes v. If the capacity
// from u to v in the residual network is positive,
// enqueue v.
v=0;
Vertex fim = garfo->getIteratorEnd(u)->getDestino();
for(std::list<Edge>::iterator passador = garfo->getIterator(u); passador->getDestino() != fim; passador++) {
printf("%d %d\n",v, cor[v]);
if (cor[v]==NOVO_V && passador->getFluxo()==false) {
push(v);
caminho[v] = u;
v++;
}
}
}
// If the color of the target node is black now,
// it means that we reached it.
return cor[end]==BLACK;
}
int main(){
int numVertexes, numConnections,i,k,numProblems,numCriticPoints, criticPoint;
char c;
int v1,v2;
scanf("%d %d",&numVertexes,&numConnections);
Graph* garfo= new Graph(numVertexes,numConnections);
Q= (int*)malloc(sizeof(Vertex)*numVertexes);
cor= (int*)malloc(sizeof(Vertex)*numVertexes);
caminho= (int*)malloc(sizeof(Vertex)*numVertexes);
for(i = 0; i < numConnections;i++){
scanf("%d %d",&v1,&v2);
garfo->addConnection(v1, v2);
}
printf("haha");
printf("%d",(int) garfo);
bfs(0,3,4, garfo);
scanf("%d",&numProblems);
for(i = 0; i < numProblems;i++){
scanf("%d ",&numCriticPoints);
while((c = getchar()) != -1){
//if(c == " "){
//}
}
}
return 0;
}