#define pii pair<int, int> #define mp make_pair #define pb push_back #define fr first #define sc second
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
map<ll, bool> vis; #define N 200007 int a[N];
inlinevoidwork(){ int n = rd(); ll sum = 0; vis.clear(); vis[0] = 1; for (int i = 1; i <= n; ++i) { a[i] = rd(); if (i % 2) a[i] = -a[i]; } for (int i = 1; i <= n; ++i) { sum += a[i]; if (vis[sum]) {puts("YES"); return;} vis[sum] = 1; } puts("NO"); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
#define pii pair<int, int> #define mp make_pair #define pb push_back #define fr first #define sc second
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 1007 ll dis[N][N]; bool vis[N][N]; int s[N]; vector<pii> e[N]; priority_queue<pair<ll, pii> > q;
inlinevoidwork(){ int n = rd(), m = rd(); for (int i = 1; i <= n; ++i) { e[i].clear(); for (int j = 1; j <= 1000; ++j) { dis[i][j] = 1e18; vis[i][j] = 0; } } for (int i = 1; i <= m; ++i) { int u = rd(), v = rd(), w = rd(); e[u].pb(mp(v, w)); e[v].pb(mp(u, w)); } for (int i = 1; i <= n; ++i) s[i] = rd(); dis[1][s[1]] = 0; q.push(mp(0, mp(1, s[1]))); while (!q.empty()) { int u = q.top().sc.fr, ss = q.top().sc.sc; q.pop(); if (vis[u][ss]) continue; vis[u][ss] = 1; for (auto [v, w] : e[u]) { if (dis[u][ss] + 1ll * w * ss < dis[v][min(ss, s[v])]) { dis[v][min(ss, s[v])] = dis[u][ss] + 1ll * w * ss; q.push(mp(-dis[v][min(ss, s[v])], mp(v, min(ss, s[v])))); } } } ll ans = 1e18; for (int i = 1; i <= 1000; ++i) ans = min(ans, dis[n][i]); printf("%lld\n", ans); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
Post title:CF Round 918
Post author:Eva.Q
Create time:2023-12-30 12:16:10
Post link:https://qyy/2023/12/30/CF/CF-Round918-Div4/
Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.