窝代码是
#include <bits/stdc++.h>
using namespace std;
//#define Fread
#ifdef Fread
char buf[1 << 21], *iS, *iT;
#define gc() (iS == iT ? (iT = (iS = buf) + fread (buf, 1, 1 << 21, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
#endif // Fread
template <typename T>
void r1(T &x) {
x = 0;
char c(getchar());
int f(1);
for(; c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
for(; '0' <= c && c <= '9';c = getchar()) x = (x * 10) + (c ^ 48);
x *= f;
}
template <typename T,typename... Args> inline void r1(T& t, Args&... args) {
r1(t); r1(args...);
}
const int maxn = 4e5 + 5;
#define int long long
int n[10], m;
int a[10][maxn];
#define mp make_pair
map<pair<int, int> , int> vis;
int f[10][maxn];
struct Node {
int id, val;
int operator < (const Node &z) const {
return val == z.val ? id < z.id : val < z.val;
}
};
set<Node> q;
const int inf = 2e9;
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
int i, j;
int mx(0);
for(i = 1; i <= 4; ++ i) r1(n[i]), mx = max(mx, n[i]);
for(i = 1; i <= 4; ++ i) {
for(j = 1; j <= n[i]; ++ j) r1(a[i][j]);
}
for(int z = 1; z <= 3; ++ z) {
r1(m);
for(i = 1; i <= m; ++ i) {
int u, v;
r1(u), r1(v);
vis[make_pair(u + mx * (z - 1), v + mx * z)] = 1;
vis[make_pair(v + mx * z, u + mx * (z - 1))] = 1;
}
}
for(i = 1; i <= n[1]; ++ i) f[1][i] = a[1][i];
for(i = 1; i <= n[1]; ++ i) {
q.insert((Node) {i, f[1][i]});
}
for(i = 2; i <= 4; ++ i) {
for(j = 1; j <= n[i]; ++ j) {
int flag(0);
for(set<Node> :: iterator it = q.begin(); it != q.end(); ++ it) {
pair<int, int> z(make_pair(it -> id + mx * (i - 2), j + mx * (i - 1)));
if(vis.count(z)) continue;
else {f[i][j] = it -> val + a[i][j]; flag = 1; break;}
}
if(!flag) f[i][j] = inf;
}
q.clear();
// q = null;
for(j = 1; j <= n[i]; ++ j) if(f[i][j] < inf) {
q.insert((Node) {j, f[i][j]});
}
}
if(q.empty() || q.begin()->val >= inf) return puts("-1"), 0;
printf("%lld\n", q.begin()->val);
return 0;
}
对于 Node 的重载部分,如果改成
val < z.val
就错了
求大佬帮助