QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641062 | #8038. Hammer to Fall | tieguodundae | TL | 35ms | 21264kb | C++23 | 2.5kb | 2024-10-14 18:13:49 | 2024-10-14 18:13:52 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", print_args(__VA_ARGS__)
template <class... T>
void print_args(T... args) { ((cerr << args << ' '), ...) << '\n'; }
using u32 = unsigned;
using u64 = unsigned long long;
using i64 = long long;
using i128 = __int128_t;
const int mod = 998244353;
const int MAXN = 1e5 + 10;
int n, m, q;
int u[MAXN], v[MAXN], w[MAXN];
int a[MAXN], b[MAXN], deg[MAXN], dp[MAXN];
multiset<int> st[MAXN];
vector<pii> g[MAXN], g2[MAXN];
void solve() {
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
deg[u]++, deg[v]++;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
for (int i = 1; i <= q; i++) {
cin >> b[i];
}
dp[b[q]] = 1e18;
int B = sqrt(n + 1);
for (int i = 1; i <= n; i++) {
if (deg[i] > B) { // 不超过2m/B个
for (auto [j, w] : g[i]) {
st[i].insert(dp[j] + w);
}
}
for (auto [j, w] : g[i]) {
if (deg[j] > B) {
g2[i].push_back({j, w});
}
}
}
/*
dp:时间i之前在u点,i时刻离开u点,并且在之后的时间都安全的后缀最小值
如果下一秒这个地方被砸,那么u点一定转移到相邻的点最优
dp[i - 1][j] <- dp[i][j]
dp[i - 1][j] <- dp[i][k](k是j的邻居)
*/
for (int i = q; i; i--) {
int u = b[i];
int pre = dp[u];
int res = 1e18;
if (deg[u] <= B) { // 度 <= sqrt(n),那么可以暴力枚举邻居,更新权值
for (auto [v, w] : g[u]) {
res = min(res, dp[v] + w);
}
} else {
res = min(res, *st[u].begin());
}
for (auto [v, w] : g2[u]) {
st[v].erase(st[v].find(pre + w));
st[v].insert(res + w);
}
dp[u] = res;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (dp[i] == 1e18) continue;
ans += dp[i] * a[i] % mod;
ans %= mod;
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11768kb
input:
3 2 2 1 1 1 2 3 10 1 2 1 3 2
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 11880kb
input:
2 1 10 5000 5000 1 2 10000 1 2 2 1 2 2 1 1 1 2
output:
550000000
result:
ok single line: '550000000'
Test #3:
score: 0
Accepted
time: 2ms
memory: 11768kb
input:
10 10 10 5 14 99 14 18 4 58 39 48 60 2 4 4 6 9 56 10 8 34 7 5 96 1 3 26 3 7 92 6 8 4 5 1 72 7 6 39 7 2 93 8 8 9 10 2 2 5 9 2 3
output:
8810
result:
ok single line: '8810'
Test #4:
score: 0
Accepted
time: 6ms
memory: 11832kb
input:
100 500 10000 89 61 65 85 89 2 32 97 13 70 29 86 68 74 84 64 54 39 26 84 56 95 73 11 70 26 60 40 84 58 68 33 65 71 55 2 11 71 49 85 14 59 38 11 60 8 81 78 27 32 52 49 35 94 62 72 64 50 12 45 77 74 92 67 92 38 81 39 12 29 60 70 53 33 25 60 7 83 4 85 47 32 13 58 85 86 44 68 44 1 81 62 97 7 66 62 5 16 ...
output:
609241
result:
ok single line: '609241'
Test #5:
score: 0
Accepted
time: 35ms
memory: 21264kb
input:
100000 100000 100000 134299012 740620432 241626312 533601686 901212368 274154852 46613593 72208460 685661661 930069933 934386896 140544225 900179749 8735320 54649110 922673925 450551589 517879800 773426781 410723403 783459037 344315202 75310230 122339501 113898579 646500753 18238713 119326471 969272...
output:
641103242
result:
ok single line: '641103242'
Test #6:
score: -100
Time Limit Exceeded
input:
448 100000 100000 411038009 847809848 901622409 143987890 230747977 330204397 58948994 635255827 124637955 446506876 693363517 282765360 687916399 598850473 404480258 958197468 332242997 7338874 321860348 37384562 440321061 434694843 935461053 803393359 852456369 428568442 233194935 663299156 907095...