Pagini recente » Rating informatica (chiuveta) | Cod sursa (job #2596357) | Cod sursa (job #2338342) | Cod sursa (job #2404937) | Cod sursa (job #1392982)
#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;
}