j模拟T4 10分,帮忙改一下

#include
#include

using namespace std;

// 计算员工的反馈意见
int calculateFeedback(int employeeId, const vector<vector>& employees) {
if (employees[employeeId][0] == 0) {
return employees[employeeId][1];
}
vector subordinates;
for (int i = 1; i < employees.size(); i++) {
if (employees[i][0] == employeeId) {
subordinates.push_back(i);
}
}
if (subordinates.empty()) {
return employees[employeeId][1];
}
int supportCount = 0;
for (int subordinate : subordinates) {
supportCount += calculateFeedback(subordinate, employees);
}
if (supportCount * 2 < subordinates.size()) {
return 0;
} else if (supportCount * 2 > subordinates.size()) {
return 1;
} else {
return employees[employeeId][1];
}
}

// 判断员工意见是否有意义
bool isOpinionMeaningful(int employeeId, vector<vector>& employees) {
int originalFeedback = calculateFeedback(0, employees);
employees[employeeId][1] = 1 - employees[employeeId][1];
int newFeedback = calculateFeedback(0, employees);
employees[employeeId][1] = 1 - employees[employeeId][1];
return originalFeedback!= newFeedback;
}

int main() {
freopen(“vote.in”,“r”,stdin);
freopen(“vote.out”,“w”,stdout);
int n;
cin >> n;
vector<vector> employees(n + 1, vector(3));
for (int i = 1; i <= n; i++) {
cin >> employees[i][0] >> employees[i][1] >> employees[i][2];
}
for (int i = 1; i <= n; i++) {
if (isOpinionMeaningful(i, employees)) {
cout << employees[i][2] << endl;
} else {
cout << 0 << endl;
}
}
return 0;
}

AI写的?

感觉是,头文件都没写全,变量名还这么长

实在想不出来啊

唉,不说你了,AI写的还帮忙改