QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641053 | #8038. Hammer to Fall | tieguodundae | WA | 4ms | 11864kb | C++23 | 2.3kb | 2024-10-14 18:07:16 | 2024-10-14 18:07:18 |
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 a[MAXN], b[MAXN], deg[MAXN], dp[MAXN];
multiset<int> st[MAXN];
vector<pii> g[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);
}
}
}
/*
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);
}
for (auto [v, w] : g[u]) {
if (deg[v] > B) {
st[v].erase(st[v].find(pre + w));
st[v].insert(res + w);
}
}
} else {
res = min(res, *st[u].begin());
}
dp[u] = res;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
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: 11864kb
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: 2ms
memory: 11856kb
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: 11824kb
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: -100
Wrong Answer
time: 4ms
memory: 11844kb
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:
114526
result:
wrong answer 1st lines differ - expected: '609241', found: '114526'