QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#631164#8038. Hammer to FallIron_gainerRE 2ms11880kbC++201.6kb2024-10-11 22:27:142024-10-11 22:27:16

Judging History

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

  • [2024-10-11 22:27:16]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:11880kb
  • [2024-10-11 22:27:14]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<array>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void speed()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
vector<pii>edge[100005];
multiset<ll>s[100005];
ll a[100005];
int b[100005];
int in[100005];
ll dp[100005];
constexpr int mod = 998244353;
int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	int B = sqrt(m);
	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;
		edge[u].push_back({ v,w });
		edge[v].push_back({ u,w });
		in[u]++;
		in[v]++;
	}
	for (int i = 1; i <= q; i++)
	{
		cin >> b[i];
	}
	for (int i = 1; i <= n; i++)
	{
		if (in[i]>B)
		{
			for (auto j : edge[i])
			{
				if (in[j.first] <= B)
					s[i].insert(j.second);
			}
		}
	}
	for (int i = q; i >= 1; i--)
	{
		if (in[b[i]]<=B)
		{
			for (auto j : edge[b[i]])
			{
				if (in[j.first] > B)s[j.first].erase(s[j.first].find(dp[b[i]]+j.second));
			}
			dp[b[i]] = 1e18;
			for (auto j : edge[b[i]])
			{
				dp[b[i]] = min(dp[b[i]], dp[j.first] + j.second);
				if (in[j.first] > B)s[j.first].insert(dp[j.first]);
			}
		}
		else
		{
			dp[b[i]] = *s[b[i]].begin();
			for (auto j : edge[b[i]])
			{
				if (in[j.first] > B) dp[b[i]] = min(dp[b[i]], dp[j.first] + j.second);
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans = (ans + dp[i] % mod * a[i] % mod) % mod;
	}
	cout << ans << endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 11880kb

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: 9856kb

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: -100
Runtime Error

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:


result: