제출 #516993

#제출 시각아이디문제언어결과실행 시간메모리
516993nightyCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
314 ms13180 KiB
#include <bits/stdc++.h> using namespace std; vector<int> last; set<pair<int, int>> choosenE; vector<long long> dijkstra(int start, vector<vector<pair<int, int>>>& g) { int n = g.size(); vector<long long> d(n, numeric_limits<long long>::max()); last.assign(n, -1); d[start] = 0; set<pair<long long, int>> s; // {d[i], i} s.insert({0, start}); while (!s.empty()) { int i = s.begin()->second; s.erase(s.begin()); for (auto [j, w] : g[i]) { if (d[i] + w < d[j]) { s.erase({d[j], j}); d[j] = d[i] + w; last[j] = i; s.insert({d[j], j}); } } } return d; } vector<long long> dijkstra2(int start, vector<vector<pair<int, int>>>& g) { int n = g.size(); vector<long long> d(n, numeric_limits<long long>::max()); last.assign(n, -1); d[start] = 0; set<pair<long long, int>> s; // {d[i], i} s.insert({0, start}); while (!s.empty()) { int i = s.begin()->second; s.erase(s.begin()); for (auto [j, w] : g[i]) { if (choosenE.find({i, j}) != choosenE.end() || choosenE.find({j, i}) != choosenE.end()) { w = 0; } if (d[i] + w < d[j]) { s.erase({d[j], j}); d[j] = d[i] + w; last[j] = i; s.insert({d[j], j}); } } } return d; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; int s, t; cin >> s >> t; --s, --t; int u, v; cin >> u >> v; --u, --v; vector<vector<pair<int, int>>> g(n); for (int _m = 0; _m < m; ++_m) { int a, b, w; cin >> a >> b >> w; --a, --b; g[a].push_back({b, w}); g[b].push_back({a, w}); } dijkstra(s, g); while (s >= 0) { choosenE.insert({last[s], s}); s = last[s]; } auto d = dijkstra2(u, g); cout << d[v] << '\n'; return 0; }

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

commuter_pass.cpp: In function 'std::vector<long long int> dijkstra(int, std::vector<std::vector<std::pair<int, int> > >&)':
commuter_pass.cpp:19:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |         for (auto [j, w] : g[i]) {
      |                   ^
commuter_pass.cpp: In function 'std::vector<long long int> dijkstra2(int, std::vector<std::vector<std::pair<int, int> > >&)':
commuter_pass.cpp:41:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |         for (auto [j, w] : g[i]) {
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...