QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#399095#8038. Hammer to FallHqwqTL 0ms0kbC++201.3kb2024-04-25 21:54:102024-04-25 21:54:11

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 21:54:11]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-04-25 21:54:10]
  • 提交

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

output:


result: