이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
vector<vector<int>> G(n);
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
--a, --b;
G[a].pb(b);
G[b].pb(a);
}
// time, minalt, v
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> q;
q.push({0, 0, 0});
vector<bool> vis(n);
vis[0] = 1;
int ans = INT_MAX;
while(!q.empty()){
auto [time, minalt, u] = q.top(); q.pop();
// cout << u << ' ' <<
for(int v : G[u]){
if(vis[v]) continue;
if(v == n-1){
ans = min(ans, time + minalt + (minalt == 0));
} else if(time < a[v] - 1){
vis[v] = 1;
q.push({a[v], a[v], v});
} else{
vis[v] = 1;
q.push({time+1, max(max(minalt-1, a[v]), 0), v});
}
}
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:33:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | auto [time, minalt, u] = q.top(); q.pop();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |