이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)3e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, m, k, s, t, ans, Q, d[N];
vector<pii> g[N];
bool used[N];
void dfs(int v, int mn) {
used[v] = 1;
mn = min(mn, d[v]);
if(v == t) {
ans = max(ans, mn);
}
for(auto [to, w] : g[v]) {
if(!used[to]) {
dfs(to, mn);
}
}
used[v] = 0;
}
void solve() {
cin >> n >> m;
map<pii, bool> was;
for(int i = 1; i <= m; ++i) {
int u, v, w;
cin >> u >> v >> w;
was[{u, v}] = was[{v, u}] = 1;
g[u].pb({v, w});
g[v].pb({u, w});
}
cin >> k;
for(int i = 1; i <= n; ++i) d[i] = INF;
set<pii> q;
for(int i = 1; i <= k; ++i) {
int x;
cin >> x;
d[x] = 0;
q.insert({0, x});
}
while(!q.empty()) {
int v = (*q.begin()).y;
q.erase(q.begin());
for(auto [to, w] : g[v]) {
if(d[v] + w < d[to]) {
q.erase({d[to], to});
d[to] = d[v] + w;
q.insert({d[to], to});
}
}
}
cin >> Q;
while(Q--) {
cin >> s >> t;
if(was[{s, t}]) cout << min(d[s], d[t]) << nl;
else {
fill(used + 1, used + 1 + n, 0);
ans = -INF;
dfs(s, d[s]);
cout << ans << nl;
}
}
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'void dfs(long long int, long long int)':
plan.cpp:36:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
36 | for(auto [to, w] : g[v]) {
| ^
plan.cpp: In function 'void solve()':
plan.cpp:66:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for(auto [to, w] : g[v]) {
| ^
# | 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... |