이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pb emplace_back
#define All(x) x.begin(), x.end()
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 100000;
const int INF = 1e18;
int n, m, k, q;
int a, b, c;
vector <pii> path[MAXN+1];
vector <int> arr[MAXN+1];
vector <pii> qry;
int v[MAXN+1];
int dsu[MAXN+1];
int mmin[MAXN+1];
int ans[MAXN];
priority_queue <pii, vector<pii>, greater<pii>> nxt;
vector <tuple<int,int,int>> E;
void init() {
for (int i = 1; i <= n; i++)
v[i] = INF;
for (int i = 1; i <= n; i++)
dsu[i] = i;
}
void dijkstra() {
while (nxt.size()) {
auto [d, now] = nxt.top();
nxt.pop();
if (d > v[now]) continue;
for (auto [i, c] : path[now]) {
if (v[i] > d + c) {
v[i] = d + c;
nxt.emplace(v[i], i);
}
}
}
}
int fnd(int a) {
return dsu[a] == a ? a : dsu[a] = fnd(dsu[a]);
}
void Merge(int a, int b) {
a = fnd(a), b = fnd(b);
if (a == b) return;
if (arr[a].size() < arr[b].size()) {
mmin[b] = min(mmin[b], mmin[a]);
for (int i : arr[a]) {
auto [x, y] = qry[i];
if (fnd(x) + fnd(y) == a + b) {
ans[i] = mmin[b];
} else if (fnd(x) != fnd(y)) {
arr[b].pb(i);
}
}
dsu[a] = b;
} else {
mmin[a] = min(mmin[a], mmin[b]);
for (int i : arr[b]) {
auto [x, y] = qry[i];
if (fnd(x) + fnd(y) == a + b) {
ans[i] = mmin[a];
} else if (fnd(x) != fnd(y)) {
arr[a].pb(i);
}
}
dsu[b] = a;
}
}
void solve() {
for (int i = 1; i <= n; i++) {
mmin[i] = v[i];
for (auto [j, c] : path[i]) {
if (v[i] < v[j]) continue;
E.pb(v[j], i, j);
}
}
sort(All(E), greater<tuple<int,int,int>>());
for (int i = 0; i < E.size(); i++) {
auto [o, a, b] = E[i];
Merge(a, b);
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b >> c;
path[a].pb(b, c);
path[b].pb(a, c);
}
init();
cin >> k;
for (int i = 0; i < k; i++) {
cin >> a;
v[a] = 0;
nxt.emplace(0, a);
}
dijkstra();
cin >> q;
for (int i = 0; i < q; i++) {
cin >> a >> b;
arr[a].pb(i);
arr[b].pb(i);
qry.pb(a, b);
}
solve();
for (int i = 0; i < q; i++) {
cout << ans[i] << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'void dijkstra()':
plan.cpp:37:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | auto [d, now] = nxt.top();
| ^
plan.cpp:40:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
40 | for (auto [i, c] : path[now]) {
| ^
plan.cpp: In function 'void Merge(long long int, long long int)':
plan.cpp:59:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
59 | auto [x, y] = qry[i];
| ^
plan.cpp:70:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
70 | auto [x, y] = qry[i];
| ^
plan.cpp: In function 'void solve()':
plan.cpp:84:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
84 | for (auto [j, c] : path[i]) {
| ^
plan.cpp:90:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i = 0; i < E.size(); i++) {
| ~~^~~~~~~~~~
plan.cpp:91:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
91 | auto [o, a, b] = E[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... |