QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399095 | #8038. Hammer to Fall | Hqwq | TL | 0ms | 0kb | C++20 | 1.3kb | 2024-04-25 21:54:10 | 2024-04-25 21:54:11 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, q, a[100010], b[100010], d[100010], ww[100010], vis[100010];
vector<int>e[100010], w[100010];
vector<int>da[100010];
multiset<int>s[100010];
const ll mod = 998244353;
int main() {
scanf("%lld %lld %lld", &n, &m, &q);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
for (int i = 1; i <= m; i++) {
ll u, v, www;
scanf("%lld %lld %lld", &u, &v, &www);
e[u].push_back(v);
w[u].push_back(www);
e[v].push_back(u);
w[v].push_back(www);
}
for (int i = 1; i <= q; i++) {
scanf("%lld", &b[i]);
}
ll lj = sqrt(m);
for (int i = 1; i <= n; i++) d[i] = e[i].size();
for (int i = 1; i <= n; i++) if (d[i] > lj) vis[i] = 1;
for (int i = q; i >= 1; i--) {
int x = b[i];
if (d[x] <= lj) {
ll minn = 1e18;
for (int j = 0; j < d[x]; j++) {
minn = min(minn, ww[e[x][j]] + w[x][j]);
}
for (int nx : e[x]) {
if (vis[nx]) {
s[nx].erase(s[nx].find(ww[x]));
s[nx].insert(minn);
}
}
ww[x] = minn;
}
else {
ll minn = (*s[x].begin());
for (int nx : da[x]) {
if (vis[nx]) {
s[nx].erase(s[nx].find(ww[x]));
s[nx].insert(minn);
}
}
ww[x] = minn;
}
}
ll ans = 0;
for (int i = 1; i <= n; i++)
{
ans = (ans + ww[i] * a[i]) % mod;
}
cout << ans;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3 2 2 1 1 1 2 3 10 1 2 1 3 2