Cod sursa(job #1392982)

Utilizator rootsroots1 roots Data 19 martie 2015 00:16:06
Problema Flux maxim Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <stdio.h>
#include <vector>

#define MAXN 1001

using namespace std;

int N, M;
vector <int> G[MAXN];
int c[MAXN][MAXN];
int f[MAXN][MAXN];

inline void readAndBuild() {
    scanf("%d%d", &N, &M);
    
    int x, y, z;
    while (M --) {
        scanf("%d%d%d", &x, &y, &z);
        
        if (c[y][x] != 0) while(1);

        if (c[x][y] == 0) {
            G[x].push_back(y);
            c[x][y] = z;
        } else {
            c[x][y] += z;
        }
    }
}

int main() {
    freopen("maxflow.in", "r", stdin);
    freopen("maxflow.out", "w", stdout);
    
//    readAndBuild();
    scanf("%d%d", &N, &M);
    
    int x, y, z;
    while (M --) {
        scanf("%d%d%d", &x, &y, &z);
        
        if (c[y][x] != 0) return -1;
        
        if (c[x][y] == 0) {
            G[x].push_back(y);
            c[x][y] = z;
        } else {
            c[x][y] += z;
        }
    }

    
    return 0;
}