제출 #649675

#제출 시각아이디문제언어결과실행 시간메모리
649675RealSnakeCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
2082 ms33940 KiB
#include "bits/stdc++.h" #define ll long long using namespace std; int n, m, s, t, u, v; int a[100005]; ll dist[100005], dist2[100005]; vector<pair<int, ll>> node[100005], node2[100005]; int ind; ll ans = 1e18; void solve() { for(int i = 0; i < ind - 1; i++) { int b1 = a[i], b2 = a[i + 1]; int sz = node[b1].size(); for(int j = 0; j < sz; j++) { if(node2[b1][j].first == b2) { node2[b1][j].second = 0; break; } } sz = node[b2].size(); for(int j = 0; j < sz; j++) { if(node2[b2][j].first == b1) { node2[b2][j].second = 0; break; } } } set<pair<ll, int>> ss; ss.insert({0, u}); for(int i = 1; i <= n; i++) dist2[i] = 1e18; dist2[u] = 0; while(ss.size()) { auto [dis, x] = *ss.begin(); ss.erase(ss.begin()); if(dis > dist2[x]) continue; if(x == v || dis >= ans) { ans = min(ans, dis); break; } for(auto [y, d] : node2[x]) { if(dis + d < dist2[y]) { dist2[y] = dis + d; ss.insert({dist2[y], y}); } } } for(int i = 0; i < ind - 1; i++) { int b1 = a[i], b2 = a[i + 1]; int sz = node[b1].size(); for(int j = 0; j < sz; j++) { if(node2[b1][j].first == b2) { node2[b1][j].second = node[b1][j].second; break; } } sz = node[b2].size(); for(int j = 0; j < sz; j++) { if(node2[b2][j].first == b1) { node2[b2][j].second = node[b2][j].second; break; } } } } void dfs(int x) { a[ind++] = x; if(x == t) { solve(); return; } for(auto [y, d] : node[x]) { if(dist[x] + d <= dist[y]) { dist[y] = dist[x] + d; dfs(y); } } ind--; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> s >> t >> u >> v; for(int i = 0; i < m; i++) { int a, b; ll c; cin >> a >> b >> c; node[a].push_back({b, c}); node[b].push_back({a, c}); node2[a].push_back({b, c}); node2[b].push_back({a, c}); } for(int i = 1; i <= n; i++) dist[i] = 1e18; dist[s] = 0; dfs(s); cout << ans; return 0; }

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

commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:37:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |         auto [dis, x] = *ss.begin();
      |              ^
commuter_pass.cpp:45:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |         for(auto [y, d] : node2[x]) {
      |                  ^
commuter_pass.cpp: In function 'void dfs(int)':
commuter_pass.cpp:77:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   77 |     for(auto [y, d] : node[x]) {
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...