#include<iostream>
#include<vector>
using namespace std;
struct node {
int x, y;
node(){x=0,y=0;}
node(int a, int b) { x = a; y = b; }
};
int all[1005][1005];
int cust[1005][1005];
int vis[1005][1005];
int n, m, k, dd;
vector<node> d[2];
int main() {
cin >> n >> m >> k >> dd;
int a, b, c;
node e;
while (m--) {
cin >> e.x >> e.y;
vis[e.x][e.y] = 1;
d[1].push_back(e);
}
for (int i = 1; i <= k; ++i) {
cin >> a >> b >> c;
all[a][b] = c;
}
; while (dd--) {
cin >> a >> b;
all[a][b] = -1;
}
int cnt = 0;
int tim = 0;
long long int re = 0;
while (cnt!=k) {
b = tim % 2;
a = ++tim % 2;
for (int i = 0; i < d[a].size(); ++i) {
int x = d[a][i].x, y = d[a][i].y + 1;
if (!vis[x][y] && x > 0 && x <= n && y > 0 && y <= n) {
vis[x][y] = 1;
if (all[x][y] > 0) { re += tim*all[x][y]; cnt++; }
if (all[x][y] >= 0)d[b].push_back(node(x, y));
}
y -= 2;
if (!vis[x][y] && x > 0 && x <= n && y > 0 && y <= n) {
vis[x][y] = 1;
if (all[x][y] > 0) { re += tim*all[x][y]; cnt++; }
if (all[x][y] >= 0)d[b].push_back(node(x, y));
}
y += 1; x += 1;
if (!vis[x][y] && x > 0 && x <= n && y > 0 && y <= n) {
vis[x][y] = 1;
if (all[x][y] > 0) { re += tim*all[x][y]; cnt++; }
if (all[x][y] >= 0)d[b].push_back(node(x, y));
}
x -= 2;
if (!vis[x][y] && x > 0 && x <= n && y > 0 && y <= n) {
vis[x][y] = 1;
if (all[x][y] > 0) { re += tim*all[x][y]; cnt++; }
if (all[x][y] >= 0) d[b].push_back(node(x, y));
}
}
d[a].clear();
}
cout << re << endl;
}
ccf 201409-4 最优配餐
最新推荐文章于 2021-08-18 22:25:07 发布