//#include "main.h"
#include<bits/stdc++.h>
#include <stdio.h>
#include <vector>
using namespace std;
struct pair_hash {
template<class T1, class T2>
std::size_t operator()(const std::pair<T1, T2> &p) const {
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ h2;
}
};
unordered_map<pair<int, int>, int, pair_hash> umap;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n, 0), h(n, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
//记录每个节点相邻的边
vector<vector<int>> edges(n + 1, vector<int>());
//记录两个节点的路径
unordered_map<pair<int, int>, int, pair_hash> umap;
for (int i = 0; i < m; ++i) {
int a1, a2, a3;
cin >> a1 >> a2 >> a3;
umap[{a1, a2}] = a3;
umap[{a2, a1}] = a3;
edges[a1].push_back(a2);
edges[a2].push_back(a1);
}
int res = 0;
//开始解决
//枚举中心点
for (int i = 1; i <= n; ++i) {
//枚举景点个数
for (int num = 1; num <= 3; ++num) {
if (num == 1) {
int time = 0;
int value = 0;
time += h[i - 1];
value += a[i - 1];
if (time <= k) {
res = max(res, value);
}
} else if (num == 2) {
//依次遍历一个节点
for (const auto &item: edges[i]) {
int time = 0;
int value = 0;
time += h[i - 1];
value += a[i - 1];
time += h[item - 1];
value += a[item - 1];
//两地之间路径
time += umap[{i, item}];
if (time <= k) {
res = max(res, value);
}
}
} else {//三个地点情况
for (int index1 = 0; index1 < edges[i].size(); ++index1) {
for (int index2 = index1 + 1; index2 < edges[i].size(); ++index2) {
int time = 0;
int value = 0;
time += h[i - 1] + h[edges[i][index1] - 1] + h[edges[i][index2] - 1];
value += a[i - 1] + a[edges[i][index1] - 1] + a[edges[i][index2] - 1];
//两地距离
time += umap[{i, index1}] + umap[{i, index2}];
if (time <= k) {
res = max(res, value);
// cout << res << " " << value << endl;
}
}
}
}
}
}
cout << res << endl;
return 0;
}
/*
4 4 8
4 3 2 1
1 2 3 4
1 2 1
2 3 1
2 4 1
3 4 1
*/
小红书2023-8-19笔试题3
最新推荐文章于 2024-08-31 20:59:22 发布