이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma once
#include <bits/stdc++.h>
using namespace std;
template<typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
const int64_t INF = 1e18;
pair<int64_t, int> get_dists(const vector<vector<pair<int, int>>>& graph, int n, int s=0) {
vector<int64_t> d(n, INF);
d[s] = 0;
minheap<pair<int64_t, int>> q;
q.push({0, s});
while (!q.empty()) {
pair<int64_t, int> v = q.top();
q.pop();
for (int i = 0; i < graph[v.second].size(); ++i) {
pair<int, int> u = graph[v.second][i];
if (d[u.first] > d[v.second] + u.second) {
d[u.first] = d[v.second] + u.second;
q.push({d[u.first], u.first});
}
}
}
pair<int64_t, int> ret = {-1e18, 69420123};
for (int i = 0; i < n; ++i) {
if (d[i] != INF) ret = max(ret, {d[i], i});
}
return ret;
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
vector<vector<pair<int, int>>> graph(2*n);
for (int i = 0; i+1 < n; ++i) {
graph[i].push_back({i+1, l[i]});
graph[i+1].push_back({i, l[i]});
}
for (int i = 0; i < n; ++i) {
if (d[i] > 0) graph[i].push_back({i+n, d[i]}), graph[i+n].push_back({i, d[i]});
}
int64_t res = 1e18;
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
graph[i].push_back({j, c});
graph[j].push_back({i, c});
auto x = get_dists(graph, 2*n);
int64_t now = get_dists(graph, 2*n, x.second).first;
res = min(res, now);
graph[i].pop_back();
graph[j].pop_back();
}
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
shortcut.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
shortcut.cpp: In function 'std::pair<long int, int> get_dists(const std::vector<std::vector<std::pair<int, int> > >&, int, int)':
shortcut.cpp:18:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int i = 0; i < graph[v.second].size(); ++i) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |
# | 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... |