Pagini recente » Cod sursa (job #2688174) | Statistici Tudor Iarina Maria (iarinatudor) | Cod sursa (job #70222) | Cod sursa (job #1638361) | Cod sursa (job #1614816)
#include <fstream>
#include <list>
#include <queue>
using namespace std;
ifstream fin("maxflow.in");
ofstream fout("maxflow.out");
int n, m, x, y, c, i, crt;
int flowMat[1010][1010], arbore[1010];
bool found = true;
list<int> graf[1010];
queue<int> Q;
void makeArb() {
for (int i = 1 ; i <= n ; i++) arbore[i] = 0;
Q.push(1); arbore[1] = -1;
while (!Q.empty()) {
crt = Q.front(); Q.pop();
for (list<int>::iterator it = graf[crt].begin() ; it != graf[crt].begin() ; it++) {
if (arbore[*it] = 0) {
arbore[*it] = crt;
Q.push(*it);
}
}
}
}
int main()
{
fin>>n>>m;
for (i = 1 ; i <= m ; i++) {
fin>>x>>y>>c;
graf[x].push_back(y);
graf[y].push_back(x);
flowMat[x][y] = c;
}
do {
makeArb();
} while (found);
return 0;
}