QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694776#6523. Escape PlanShuishui#AC ✓476ms51236kbC++141.5kb2024-10-31 18:38:232024-10-31 18:38:23

Judging History

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

  • [2024-10-31 18:38:23]
  • 评测
  • 测评结果:AC
  • 用时:476ms
  • 内存:51236kb
  • [2024-10-31 18:38:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define Sz(x) (int)(x).size()
#define bit(x) (1ll << (x))
using ll = long long;
using db = double;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vd = vector<db>;
mt19937 mrand(time(0));

void solve(void)
{
	int n, m, k;
	cin >> n >> m >> k;
	const ll INF = bit(60);
	vl dis(n + 2, INF);
	priority_queue<array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> q;
	for (int i = 1; i <= k; i++)
	{
		int x;
		cin >> x;
		dis[x] = 0;
		q.push({dis[x], x});
	}
	vi d(n + 2), vis(n + 2);
	for (int i = 1; i <= n; i++)
	{
		cin >> d[i];
		if (!dis[i]) d[i] = 0;
	}

	vector<vector<array<int, 2>>> e(n + 2);
	for (int i = 1; i <= m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		e[u].pb({v, w}), e[v].pb({u, w});
	}

	while (!q.empty())
	{
		auto [ndis, u] = q.top();
		q.pop();
		if (vis[u] || d[u]) 
		{
			d[u]--;
			continue;
		}
		vis[u] = 1;
		dis[u] = ndis;
		for (auto [v, w] : e[u])
			if (dis[u] + w < dis[v])
				q.push({dis[u] + w, v});
	}
	if (dis[1] == INF)
		cout << -1 << "\n";
	else
		cout << dis[1] << "\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// cout << fixed << setprecision(10);

	int T = 1;
	cin >> T;
	for (int i = 1; i <= T; i++)
	solve();

	return 0;
}

详细

Test #1:

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

input:

2
3 4 1
3
1 1 1
1 2 1
1 2 2
2 3 1
2 3 2
3 2 2
2 3
2 0 0
1 2 1
1 3 1

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

score: 0
Accepted
time: 476ms
memory: 51236kb

input:

100
100 1808 2
94 47
3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2
72 29 1138
59 78 2398
95 5 1610
32 46 4176
36 99 8143
100 69 413
61 58 1595
9 9...

output:

5109
1021
3293
4646
3796
3394
1884
6772
2329
2067
3296
2809
865
4249
2241
3792
2135
2544
3343
1775
10602
4677
1700
2150
7071
14055
3368
2322
1113
1980
3067
1617
1702
-1
2879
6265
2065
2810
2289
3001
402
3769
18118
6874
7879
3823
-1
510
2636
10564
-1
3166
3615
7526
5549
1261
3302
270
4440
1998
3350
3...

result:

ok 100 numbers