Submission #1127768

#TimeUsernameProblemLanguageResultExecution timeMemory
1127768tsengangCommuter Pass (JOI18_commuter_pass)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define ll long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define vodka void #define ertunt return using namespace std; ll n, m, s, t, u, v; vector<set<pair<ll, ll>>> adj(100004); ll ans = 1e18; vector<ll> beff[100004]; vector<bool> visit(100004, 0); vodka brgdfs(ll x) { if (visit[x] == 1) { ertunt; } visit[x] = 1; set<pair<ll, ll>> st; vector<ll> dist(100005, 1e18); vector<bool> vis(100005, 0); st.insert({0, x}); dist[x] = 0; while (!st.empty()) { pair<ll, ll> p = *st.begin(); st.erase(p); if (vis[p.ss]) continue; vis[p.ss] = 1; for (auto [y, z] : adj[p.ss]) { if (dist[p.ss] + z < dist[y]) { dist[y] = dist[p.ss] + z; st.insert({dist[y], y}); } } } ans = min(ans, dist[v]); for (auto y : beff[x]) brgdfs(y); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> s >> t >> u >> v; for (ll i = 0; i < m; i++) { ll a, b, c; cin >> a >> b >> c; adj[a].insert({b, c}); adj[b].insert({a, c}); } set<pair<ll, ll>> st; vector<ll> dist(n + 5, 1e18); vector<bool> vis(n + 5, 0); vector<ll> bef(n + 5, -1); dist[s] = 0; st.insert({0, s}); if (u == s) { while (!st.empty()) { pair<ll, ll> p = *st.begin(); st.erase(p); if (vis[p.ss]) continue; vis[p.ss] = 1; for (auto [x, y] : adj[p.ss]) { if (dist[x] >= dist[p.ss] + y) { beff[x].pb(p.ss); dist[x] = dist[p.ss] + y; st.insert({dist[x], x}); } } } brgdfs(t); cout << ans; ertunt 0; } while (!st.empty()) { pair<ll, ll> p = *st.begin(); st.erase(p); if (vis[p.ss]) continue; vis[p.ss] = 1; for (auto [x, y] : adj[p.ss]) { if (dist[p.ss] + y < dist[x]) { dist[x] = dist[p.ss] + y; st.insert({dist[x], x}); bef[x] = p.ss; } } } vector<ll> arr; ll cur = t; while (cur > 0) { arr.pb(cur); cur = bef[cur]; } reverse(all(arr)); for (ll i = 1; i < arr.size(); i++) { ll a = arr[i - 1], b = arr[i]; auto it = adj[a].lower_bound({b, -1}); if (it != adj[a].end() && it->ff == b) adj[a].erase(it); it = adj[b].lower_bound({a, -1}); if (it != adj[b].end() && it->ff == a) adj[b].erase(it); adj[a].insert({b, 0}); adj[b].insert({a, 0}); beff[b].pb(a); } fill(all(dist), 1e18); st.clear(); dist[u] = 0; fill(all(vis), 0); st.insert({0, u}); while (!st.empty()) { pair<ll, ll> p = *st.begin(); st.erase(p); if (vis[p.ss]) continue; vis[p.ss] = 1; for (auto [x, y] : adj[p.ss]) { if (dist[p.ss] + y < dist[x]) { dist[x] = dist[p.ss] + y; st.insert({dist[x], x}); } } } cout << dist[v]; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void brgdfs(long long int)':
commuter_pass.cpp:16:9: error: reference to 'visit' is ambiguous
   16 |     if (visit[x] == 1) {
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:133,
                 from commuter_pass.cpp:1:
/usr/include/c++/11/variant:1734:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1734 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
commuter_pass.cpp:14:14: note:                 'std::vector<bool> visit'
   14 | vector<bool> visit(100004, 0);
      |              ^~~~~
commuter_pass.cpp:19:5: error: reference to 'visit' is ambiguous
   19 |     visit[x] = 1;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:133,
                 from commuter_pass.cpp:1:
/usr/include/c++/11/variant:1734:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1734 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
commuter_pass.cpp:14:14: note:                 'std::vector<bool> visit'
   14 | vector<bool> visit(100004, 0);
      |              ^~~~~