답안 #913477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913477 2024-01-20T08:04:28 Z pan Airplane (NOI23_airplane) C++17
0 / 100
11 ms 13948 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/4;
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()
{
	input(n); input(m);
	height.resize(n);
	for (ll i=1; i<=n; ++i) input(height[i]);
	for (ll i=0; i<m; ++i)
	{
		ll x, y;
		input(x); input(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, up[i] + down[i]);
	}
	// if maintain for 1 sec
	for (ll i=0; i<m; ++i)
	{
		pi x = edges[i];
		if (x.f==1 || x.s==1 || x.f==n || x.s==n) continue;
		ans = min(ans, up[x.f] + down[x.s]+1);
		ans = min(ans, up[x.s] + down[x.f]+1);
	}
	print(ans, '\n');
	
	
	
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Main.cpp:53:2: note: in expansion of macro 'input'
   53 |  input(n); input(m);
      |  ^~~~~
Main.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Main.cpp:53:12: note: in expansion of macro 'input'
   53 |  input(n); input(m);
      |            ^~~~~
Main.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Main.cpp:55:26: note: in expansion of macro 'input'
   55 |  for (ll i=1; i<=n; ++i) input(height[i]);
      |                          ^~~~~
Main.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Main.cpp:59:3: note: in expansion of macro 'input'
   59 |   input(x); input(y);
      |   ^~~~~
Main.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Main.cpp:59:13: note: in expansion of macro 'input'
   59 |   input(x); input(y);
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 13948 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 13916 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 13916 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 13948 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -