Submission #913533

# Submission time Handle Problem Language Result Execution time Memory
913533 2024-01-20T08:16:00 Z pan Airplane (NOI23_airplane) C++17
100 / 100
814 ms 40304 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
//#define input(x) scanf("%lld", &x);
//#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, m;
vector<ll> height;
vector<ll> adj[200005];
pi edges[400005];
ll const INF = LLONG_MAX/3;
vector<ll> dijkstra(ll from)
{
	vector<ll> visited(n+1, false);
	vector<ll> dist(n+1, INF);
	dist[from] = 0;
	priority_queue<pi, vector<pi>, greater<pi> > pq;
	pq.push(mp(0, from));
	while (pq.size())
	{
		ll c = pq.top().s;
		pq.pop();
		if (visited[c]) continue;
		visited[c] = true;
		for (ll u: adj[c])
		{
			ll neww = max(dist[c]+1, height[u]);
			if (dist[u]>neww)
			{
				dist[u] = neww;
				pq.push(mp(neww, u));
			}
		}
	}
	return dist;
}
int main()
{
	cin >> n >> m;
	height.resize(n+1);
	for (ll i=1; i<=n; ++i) cin >> height[i];
	for (ll i=0; i<m; ++i)
	{
		ll x, y;
		cin >> x >> y;
		edges[i].f = x, edges[i].s = y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	vector<ll> up, down;
	up = dijkstra(1); down = dijkstra(n);
	ll ans = LLONG_MAX;
	// if maintain for 0 sec
	for (ll i=2; i<n; ++i)
	{
		ans = min(ans, max(up[i], down[i])*2);
	}
	// if maintain for 1 sec
	for (ll i=0; i<m; ++i)
	{
		pi x = edges[i];
		ans = min(ans, max(up[x.f], down[x.s])*2+1);
		ans = min(ans, max(up[x.s], down[x.f])*2+1);
	}
	cout << ans << endl;
	
	
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 164 ms 23752 KB Output is correct
3 Correct 158 ms 23736 KB Output is correct
4 Correct 153 ms 23860 KB Output is correct
5 Correct 173 ms 23672 KB Output is correct
6 Correct 182 ms 23908 KB Output is correct
7 Correct 193 ms 23908 KB Output is correct
8 Correct 2 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 3 ms 7000 KB Output is correct
3 Correct 2 ms 7000 KB Output is correct
4 Correct 3 ms 7004 KB Output is correct
5 Correct 2 ms 7004 KB Output is correct
6 Correct 3 ms 7132 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 5 ms 7260 KB Output is correct
9 Correct 6 ms 7260 KB Output is correct
10 Correct 5 ms 7260 KB Output is correct
11 Correct 4 ms 7260 KB Output is correct
12 Correct 6 ms 7268 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 5 ms 7260 KB Output is correct
15 Correct 5 ms 7260 KB Output is correct
16 Correct 6 ms 7244 KB Output is correct
17 Correct 5 ms 7324 KB Output is correct
18 Correct 3 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 3 ms 7000 KB Output is correct
3 Correct 2 ms 7000 KB Output is correct
4 Correct 3 ms 7004 KB Output is correct
5 Correct 2 ms 7004 KB Output is correct
6 Correct 3 ms 7132 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 5 ms 7260 KB Output is correct
9 Correct 6 ms 7260 KB Output is correct
10 Correct 5 ms 7260 KB Output is correct
11 Correct 4 ms 7260 KB Output is correct
12 Correct 6 ms 7268 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 5 ms 7260 KB Output is correct
15 Correct 5 ms 7260 KB Output is correct
16 Correct 6 ms 7244 KB Output is correct
17 Correct 5 ms 7324 KB Output is correct
18 Correct 3 ms 7004 KB Output is correct
19 Correct 6 ms 7132 KB Output is correct
20 Correct 4 ms 7260 KB Output is correct
21 Correct 6 ms 7260 KB Output is correct
22 Correct 6 ms 7132 KB Output is correct
23 Correct 4 ms 7308 KB Output is correct
24 Correct 5 ms 7260 KB Output is correct
25 Correct 5 ms 7256 KB Output is correct
26 Correct 4 ms 7260 KB Output is correct
27 Correct 6 ms 7524 KB Output is correct
28 Correct 7 ms 7260 KB Output is correct
29 Correct 7 ms 7364 KB Output is correct
30 Correct 5 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 164 ms 23752 KB Output is correct
3 Correct 158 ms 23736 KB Output is correct
4 Correct 153 ms 23860 KB Output is correct
5 Correct 173 ms 23672 KB Output is correct
6 Correct 182 ms 23908 KB Output is correct
7 Correct 193 ms 23908 KB Output is correct
8 Correct 2 ms 7000 KB Output is correct
9 Correct 2 ms 7004 KB Output is correct
10 Correct 3 ms 7000 KB Output is correct
11 Correct 2 ms 7000 KB Output is correct
12 Correct 3 ms 7004 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 3 ms 7132 KB Output is correct
15 Correct 3 ms 7260 KB Output is correct
16 Correct 5 ms 7260 KB Output is correct
17 Correct 6 ms 7260 KB Output is correct
18 Correct 5 ms 7260 KB Output is correct
19 Correct 4 ms 7260 KB Output is correct
20 Correct 6 ms 7268 KB Output is correct
21 Correct 5 ms 7260 KB Output is correct
22 Correct 5 ms 7260 KB Output is correct
23 Correct 5 ms 7260 KB Output is correct
24 Correct 6 ms 7244 KB Output is correct
25 Correct 5 ms 7324 KB Output is correct
26 Correct 3 ms 7004 KB Output is correct
27 Correct 6 ms 7132 KB Output is correct
28 Correct 4 ms 7260 KB Output is correct
29 Correct 6 ms 7260 KB Output is correct
30 Correct 6 ms 7132 KB Output is correct
31 Correct 4 ms 7308 KB Output is correct
32 Correct 5 ms 7260 KB Output is correct
33 Correct 5 ms 7256 KB Output is correct
34 Correct 4 ms 7260 KB Output is correct
35 Correct 6 ms 7524 KB Output is correct
36 Correct 7 ms 7260 KB Output is correct
37 Correct 7 ms 7364 KB Output is correct
38 Correct 5 ms 7260 KB Output is correct
39 Correct 294 ms 29004 KB Output is correct
40 Correct 371 ms 28420 KB Output is correct
41 Correct 335 ms 28432 KB Output is correct
42 Correct 271 ms 28384 KB Output is correct
43 Correct 289 ms 28336 KB Output is correct
44 Correct 316 ms 28196 KB Output is correct
45 Correct 350 ms 28316 KB Output is correct
46 Correct 356 ms 28324 KB Output is correct
47 Correct 399 ms 28348 KB Output is correct
48 Correct 365 ms 28368 KB Output is correct
49 Correct 377 ms 29296 KB Output is correct
50 Correct 312 ms 28988 KB Output is correct
51 Correct 458 ms 29032 KB Output is correct
52 Correct 593 ms 35104 KB Output is correct
53 Correct 521 ms 33720 KB Output is correct
54 Correct 513 ms 33900 KB Output is correct
55 Correct 527 ms 34008 KB Output is correct
56 Correct 570 ms 38828 KB Output is correct
57 Correct 736 ms 39520 KB Output is correct
58 Correct 756 ms 40164 KB Output is correct
59 Correct 814 ms 40304 KB Output is correct
60 Correct 713 ms 39916 KB Output is correct
61 Correct 708 ms 39888 KB Output is correct
62 Correct 422 ms 38840 KB Output is correct
63 Correct 695 ms 39036 KB Output is correct
64 Correct 693 ms 38900 KB Output is correct
65 Correct 701 ms 39032 KB Output is correct
66 Correct 765 ms 39152 KB Output is correct
67 Correct 744 ms 40164 KB Output is correct