Cod sursa(job #1614816)

Utilizator LolkekzorChiorean Tudor Lolkekzor Data 26 februarie 2016 09:50:03
Problema Flux maxim Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#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;
}