Submission #103533

#TimeUsernameProblemLanguageResultExecution timeMemory
103533AllianceCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
1718 ms34040 KiB
// In the name of Allah. Ya ali! #include<bits/stdc++.h> #define double long double typedef long long ll; const ll MAX_N = 1e5+10; const ll MOD = 1e9+7; using namespace std; vector<pair<int,int>> g[MAX_N]; vector<int> g2[MAX_N]; vector<int> p[MAX_N]; ll dis[MAX_N]; ll m1[MAX_N]; ll d1[MAX_N]; ll d2[MAX_N]; ll m2[MAX_N]; int mark[MAX_N]; bool done[MAX_N]; int n,m,s,t,u,v; ll ans = 1e18; void dij(int start) { for(int i = 1;i<=n;++i) dis[i] = 1e18; dis[start] = 0; set<pair<ll,int>> st; for(int i = 1;i<=n;++i) st.insert({dis[i],i}); while(st.size()) { int v = (*st.begin()).second; st.erase(st.begin()); for(auto x:g[v]) { int u = x.first; ll d = dis[v]+x.second; if (dis[u]==d) p[u].push_back(v); else if (dis[u]>d) { p[u].clear(); p[u].push_back(v); st.erase({dis[u],u}); dis[u] = d; st.insert({dis[u],u}); } } } } void dfs(int v) { mark[v]++; for(auto x:g2[v]) { if (!mark[x]) dfs(x); m1[v] = min(m1[v],m1[x]); m2[v] = min(m2[v],m2[x]); } ans = min(ans,min(m1[v]+d2[v],m2[v]+d1[v])); } void addedges(int v) { done[v] = true; for(auto x:p[v]) { g2[x].push_back(v); if (!done[x]) addedges(x); } } int main() { cin >> n >> m >> s >> t >> u >> v; for(int i = 1;i<=m;++i) { int u,v,w; cin >> u >> v >> w; g[u].push_back({v,w}); g[v].push_back({u,w}); } dij(s); addedges(t); dij(u); for(int i = 1;i<=n;++i) d1[i] = m1[i] = dis[i]; dij(v); for(int i = 1;i<=n;++i) d2[i] = m2[i] = dis[i]; ans = dis[u]; dfs(s); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...