Submission #971852

# Submission time Handle Problem Language Result Execution time Memory
971852 2024-04-29T12:01:05 Z THXuan Airplane (NOI23_airplane) C++14
100 / 100
289 ms 27252 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 1e18
using namespace std;
typedef long long ll;

vector<int>adj[200005];
ll h[200005], d[200005], dd[200005];
bool visited[200005];

void solve()
{
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 1; i <= m; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) { d[i] = INF; dd[i] = INF; }
	using T = pair<ll, int>;
	priority_queue<T, vector<T>, greater<T>>pq;
	d[1] = 0;
	pq.push({ 0, 1 });
	while (pq.size()) {
		int a = pq.top().second; pq.pop();
		if (visited[a]) continue;
		visited[a] = true;
		for (auto u : adj[a]) {
			if (d[u] > max(h[u], d[a] + 1)) {
				d[u] = max(h[u], d[a] + 1);
				pq.push({ d[u], u });
			}
		}
	}
	dd[n] = 0;
	pq.push({ 0, n });
	for (int i = 1; i <= n; i++) visited[i] = false;
	while (pq.size()) {
		int a = pq.top().second; pq.pop();
		if (visited[a]) continue;
		visited[a] = true;
		for (auto u : adj[a]) {
			if (dd[u] > max(h[u], dd[a] + 1)) {
				dd[u] = max(h[u], dd[a] + 1);
				pq.push({ dd[u], u });
			}
		}
	}
	ll ans = INF;
	for (int i = 1; i <= n; i++) {
		if (d[i] == dd[i])ans = min(ans, d[i] + dd[i]);
		for (auto u : adj[i]) {
			if (d[i] == dd[u])ans = min(ans, d[i] + dd[u] + 1);
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;// cin>>t;
	while (t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 57 ms 19396 KB Output is correct
3 Correct 60 ms 19792 KB Output is correct
4 Correct 60 ms 20048 KB Output is correct
5 Correct 64 ms 20336 KB Output is correct
6 Correct 61 ms 20460 KB Output is correct
7 Correct 61 ms 20308 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9816 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 3 ms 9816 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 3 ms 9816 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 3 ms 9820 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 2 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9816 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 3 ms 9816 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 3 ms 9816 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 3 ms 9820 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 2 ms 9820 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 3 ms 9816 KB Output is correct
21 Correct 3 ms 9816 KB Output is correct
22 Correct 3 ms 9816 KB Output is correct
23 Correct 3 ms 9816 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9820 KB Output is correct
26 Correct 3 ms 10020 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 4 ms 9820 KB Output is correct
29 Correct 3 ms 9820 KB Output is correct
30 Correct 3 ms 9876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 57 ms 19396 KB Output is correct
3 Correct 60 ms 19792 KB Output is correct
4 Correct 60 ms 20048 KB Output is correct
5 Correct 64 ms 20336 KB Output is correct
6 Correct 61 ms 20460 KB Output is correct
7 Correct 61 ms 20308 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 2 ms 9820 KB Output is correct
10 Correct 2 ms 9820 KB Output is correct
11 Correct 2 ms 9816 KB Output is correct
12 Correct 2 ms 9820 KB Output is correct
13 Correct 2 ms 9820 KB Output is correct
14 Correct 3 ms 9816 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 4 ms 9816 KB Output is correct
17 Correct 3 ms 9816 KB Output is correct
18 Correct 3 ms 9820 KB Output is correct
19 Correct 3 ms 9816 KB Output is correct
20 Correct 3 ms 9820 KB Output is correct
21 Correct 3 ms 9820 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 3 ms 9820 KB Output is correct
25 Correct 4 ms 9820 KB Output is correct
26 Correct 2 ms 9820 KB Output is correct
27 Correct 3 ms 9820 KB Output is correct
28 Correct 3 ms 9816 KB Output is correct
29 Correct 3 ms 9816 KB Output is correct
30 Correct 3 ms 9816 KB Output is correct
31 Correct 3 ms 9816 KB Output is correct
32 Correct 5 ms 9820 KB Output is correct
33 Correct 5 ms 9820 KB Output is correct
34 Correct 3 ms 10020 KB Output is correct
35 Correct 4 ms 9820 KB Output is correct
36 Correct 4 ms 9820 KB Output is correct
37 Correct 3 ms 9820 KB Output is correct
38 Correct 3 ms 9876 KB Output is correct
39 Correct 140 ms 20560 KB Output is correct
40 Correct 94 ms 19704 KB Output is correct
41 Correct 118 ms 19680 KB Output is correct
42 Correct 142 ms 19628 KB Output is correct
43 Correct 103 ms 19804 KB Output is correct
44 Correct 117 ms 19792 KB Output is correct
45 Correct 126 ms 19680 KB Output is correct
46 Correct 129 ms 19808 KB Output is correct
47 Correct 98 ms 19700 KB Output is correct
48 Correct 97 ms 19540 KB Output is correct
49 Correct 142 ms 20680 KB Output is correct
50 Correct 162 ms 20564 KB Output is correct
51 Correct 168 ms 20420 KB Output is correct
52 Correct 196 ms 23496 KB Output is correct
53 Correct 201 ms 22216 KB Output is correct
54 Correct 217 ms 22332 KB Output is correct
55 Correct 201 ms 22472 KB Output is correct
56 Correct 271 ms 26056 KB Output is correct
57 Correct 238 ms 26244 KB Output is correct
58 Correct 236 ms 27252 KB Output is correct
59 Correct 265 ms 27236 KB Output is correct
60 Correct 218 ms 27192 KB Output is correct
61 Correct 289 ms 26852 KB Output is correct
62 Correct 228 ms 26064 KB Output is correct
63 Correct 248 ms 26056 KB Output is correct
64 Correct 264 ms 26208 KB Output is correct
65 Correct 240 ms 26100 KB Output is correct
66 Correct 266 ms 26056 KB Output is correct
67 Correct 274 ms 26316 KB Output is correct