제출 #1188943

#제출 시각아이디문제언어결과실행 시간메모리
1188943caterpillowAirplane (NOI23_airplane)C++20
63 / 100
1093 ms37180 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n, m; int h[maxn], dist0[maxn], dist1[maxn], alt0[maxn], alt1[maxn]; vector<int> adj[maxn]; main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; if (n == 1) cout << "0\n", exit(0); for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].push_back(v); adj[v].push_back(u); } using t3 = tuple<int, int, int>; auto funny_dijkstra = [&] (int s, int dist[], int alt[]) { priority_queue<t3> pq; pq.push({-h[s], h[s], s}); while (pq.size()) { auto [d, a, u] = pq.top(); pq.pop(); if (dist[u] < -d) continue; dist[u] = -d, alt[u] = a; for (int v : adj[u]) { int ndist = max(-d + 1, h[v]); if (ndist < dist[v]) pq.push({-ndist, max(alt[u], h[v]), v}); } } }; memset(dist0, 0x3f, sizeof(dist0)); memset(dist1, 0x3f, sizeof(dist1)); funny_dijkstra(0, dist0, alt0); funny_dijkstra(n - 1, dist1, alt1); int ans = 1e9; for (int i = 0; i < n; i++) { if (alt0[i] == alt1[i]) ans = min(ans, dist0[i] + dist1[i]); } cout << ans << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...