0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-05 03:06:26 +00:00
OI-codes/LibreOJ/115/data/spj.js

52 lines
1.7 KiB (Stored with Git LFS)
JavaScript

exports.main = () => {
let a = input.split('\n').map(x => x.trim()).filter(x => x);
let [n, m] = a[0].split(' ').map(x => parseInt(x));
let flow = Array(n), edges = Array(m);
for (let i = 0; i < n; i++) flow[i] = 0;
for (let i = 0; i < m; i++) {
let x = a[i + 1].split(' ');
edges[i] = {
from: parseInt(x[0]),
to: parseInt(x[1]),
lower: parseInt(x[2]),
upper: parseInt(x[3])
};
}
let ans = answer.split('\n').map(x => x.trim()).filter(x => x);
let out = user_out.split('\n').map(x => x.trim()).filter(x => x);
if (ans[0] === 'NO') {
if (out[0] !== 'NO') exit({ score: 0, message: `Wrong Answer - expected 'NO' but got '${out[0]}'` });
else exit({ score: 100 });
} else {
if (out.length !== ans.length) exit({ score: 0, message: `Presentation error - expected ${ans.length} lines of output` });
for (let i = 0; i < m; i++) {
let f = parseInt(out[i + 1]);
if (!(f >= edges[i].lower && f <= edges[i].upper)) {
exit({ score: 0, message: `Wrong Answer - The flow of edge ${i + 1} should between ${edges[i].lower} and ${edges[i].upper}` });
}
flow[edges[i].from - 1] -= f;
flow[edges[i].to - 1] += f;
}
for (let i = 0; i < n; i++) {
// console.log("%d -> %d", i, flow[i]);
if (flow[i] != 0) exit({ score: 0, message: `Wrong Answer - The in-flow of node ${i + 1} is not equal to its out-flow` });
}
exit({ score: 100 });
}
};
/*
let fs = require('fs');
global.input = fs.readFileSync('data/1.in').toString();
global.user_out = fs.readFileSync('data/1.out').toString();
global.answer = fs.readFileSync('data/1.out').toString();
function exit(o) { console.log(o), process.exit(); }
exports.main();
*/