Submission #1008939

#TimeUsernameProblemLanguageResultExecution timeMemory
1008939andecaandeciCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
166 ms22356 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<ll,ll> #define fi first #define sec second const ll MOD = 998244353; const ll N = 2e5 + 5; const ll INF = 1e18; vector<pii>adj[N]; ll dist[N], dist2[N]; int32_t main(){ cin.tie(0)->sync_with_stdio(0); int tc = 1; // cin >> tc; while(tc--){ ll n,m; cin >> n >> m; ll s,t; cin >> s >> t; ll u,v; cin >> u >> v; for(int i=1;i<=m;i++){ ll a,b,w; cin >> a >> b >> w; adj[a].pb({b,w}); adj[b].pb({a,w}); } for(int i=1;i<=n;i++) dist[i] = dist2[i] = INF; dist[s] = 0; set<pii>st; st.insert({dist[s], s}); while(!st.empty()){ auto x = *st.begin(); st.erase(x); if(dist[x.sec] != x.fi) continue; for(auto i : adj[x.sec]){ if(dist[i.fi] > dist[x.sec] + i.sec){ dist[i.fi] = dist[x.sec] + i.sec; st.insert({dist[i.fi], i.fi}); } } } ll cur = t; while(cur != s){ for(auto i : adj[cur]){ if(dist[i.fi] == dist[cur] - i.sec){ i.sec = 0; cur = i.fi; break; } } } dist2[u] = 0; st.insert({dist2[u], u}); while(!st.empty()){ auto x = *st.begin(); st.erase(x); for(auto i : adj[x.sec]){ if(dist2[i.fi] > dist2[x.sec] + i.sec){ dist2[i.fi] = dist2[x.sec] + i.sec; st.insert({dist2[i.fi], i.fi}); } } } cout << dist2[v] << "\n"; } } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...