Submission #886035

# Submission time Handle Problem Language Result Execution time Memory
886035 2023-12-11T12:05:36 Z vjudge1 Airplane (NOI23_airplane) C++17
100 / 100
629 ms 31684 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()

int main(){
	int n, m;
	cin>>n>>m;

	vector<int> v(n);
	vector<vector<int>> g(n);
	for(auto &e:v) cin>>e;
	for(int i=0; i<m; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	vector<int> ans(n, -1), ans2(n, -1), tm(n, -1), tm2(n, -1);
	priority_queue<tuple<int, int, int>> pq;
	pq.push({0, 0, 0});
	while(pq.size()){
		auto [t, h, cur]=pq.top();
		pq.pop();

		if(tm[cur]!=-1) continue;
		t=tm[cur]=-t;
		h=ans[cur]=-h;

		for(auto ch:g[cur]){
			pq.push({-max(v[ch], t+1), -max(h, v[ch]), ch});
		}
	}

	pq.push({0, 0, n-1});
	while(pq.size()){
		auto [t, h, cur]=pq.top();
		pq.pop();

		if(tm2[cur]!=-1) continue;
		h=ans2[cur]=-h;
		t=tm2[cur]=-t;

		for(auto ch:g[cur]){
			pq.push({-max(v[ch], t+1), -max(h, v[ch]), ch});
		}
	}

	int res=INT_MAX;
	for(int i=0; i<n; i++){
		res=min(res, tm[i]+tm2[i]+abs(ans[i]-ans2[i]));
	}
	cout<<res<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 141 ms 15128 KB Output is correct
3 Correct 151 ms 18740 KB Output is correct
4 Correct 156 ms 19220 KB Output is correct
5 Correct 167 ms 19540 KB Output is correct
6 Correct 170 ms 19348 KB Output is correct
7 Correct 169 ms 19340 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 452 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 444 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 556 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 5 ms 860 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 452 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 444 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 556 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 5 ms 860 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 3 ms 448 KB Output is correct
23 Correct 3 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 604 KB Output is correct
27 Correct 4 ms 604 KB Output is correct
28 Correct 4 ms 700 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 5 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 141 ms 15128 KB Output is correct
3 Correct 151 ms 18740 KB Output is correct
4 Correct 156 ms 19220 KB Output is correct
5 Correct 167 ms 19540 KB Output is correct
6 Correct 170 ms 19348 KB Output is correct
7 Correct 169 ms 19340 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 452 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 444 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 556 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 4 ms 604 KB Output is correct
24 Correct 5 ms 860 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 3 ms 448 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 4 ms 604 KB Output is correct
36 Correct 4 ms 700 KB Output is correct
37 Correct 4 ms 604 KB Output is correct
38 Correct 5 ms 700 KB Output is correct
39 Correct 289 ms 19640 KB Output is correct
40 Correct 209 ms 18840 KB Output is correct
41 Correct 230 ms 19028 KB Output is correct
42 Correct 225 ms 18768 KB Output is correct
43 Correct 211 ms 18720 KB Output is correct
44 Correct 232 ms 19184 KB Output is correct
45 Correct 229 ms 18512 KB Output is correct
46 Correct 238 ms 18768 KB Output is correct
47 Correct 227 ms 18832 KB Output is correct
48 Correct 231 ms 18556 KB Output is correct
49 Correct 308 ms 19756 KB Output is correct
50 Correct 283 ms 19464 KB Output is correct
51 Correct 244 ms 19456 KB Output is correct
52 Correct 453 ms 24616 KB Output is correct
53 Correct 437 ms 24796 KB Output is correct
54 Correct 429 ms 24324 KB Output is correct
55 Correct 478 ms 22220 KB Output is correct
56 Correct 607 ms 26060 KB Output is correct
57 Correct 601 ms 27596 KB Output is correct
58 Correct 580 ms 28108 KB Output is correct
59 Correct 590 ms 28788 KB Output is correct
60 Correct 629 ms 31684 KB Output is correct
61 Correct 609 ms 26828 KB Output is correct
62 Correct 571 ms 29172 KB Output is correct
63 Correct 581 ms 30832 KB Output is correct
64 Correct 607 ms 30264 KB Output is correct
65 Correct 585 ms 31100 KB Output is correct
66 Correct 592 ms 27084 KB Output is correct
67 Correct 605 ms 26436 KB Output is correct