Submission #229861

#TimeUsernameProblemLanguageResultExecution timeMemory
229861davooddkareshkiCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
2094 ms20088 KiB
// be name khoda #include<bits/stdc++.h> using namespace std; #define F first #define S second //#define mp make_pair typedef long long ll; #define int long long #pragma GCC optimize("Ofast") const int maxn = 1e5+10; const int mod = 1e9+7; const ll inf = 1e18+10; //const int N = 2e6+10; int n, m, k; int a[maxn], b[maxn], dis[maxn], D[maxn]; int Ss, T, U, V; vector<pair<int,int>> g[maxn]; vector<int> g2[maxn]; void dijkstra(int s, char tp) { fill(D,D+maxn,inf); set<pair<int,int>> se; D[s] = 0; se.insert({0,s}); while(se.size()) { int v = se.begin()->S; se.erase({dis[v],v}); for(auto e : g[v]) { int u = e.F, w = e.S; if(D[v] + w < D[u]) { se.erase({D[u],u}); D[u] = D[v] + w; se.insert({D[u],u}); } } } if(tp == 'S') for(int i = 1; i <= n; i++) dis[i] = D[i]; if(tp == 'V') for(int i = 1; i <= n; i++) a[i] = D[i]; if(tp == 'U') for(int i = 1; i <= n; i++) b[i] = D[i]; } bool mark[maxn], ctn[maxn]; int mn[maxn]; ll ans = inf; void dfs(int v) { mn[v] = b[v]; for(auto u : g2[v]) if(!mark[u]) { dfs(u); mn[v] = min(mn[v],mn[u]); (ctn[v] |= ctn[u]); } if(v == T) ctn[v] = 1; if(ctn[v]) ans = min(ans,a[v]+mn[v]); } signed main() { // ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>> n >> m >> Ss >> T >> U >> V; //cout<<"SDFg"; for(int i = 1, u, v, w; i <= m; i++) { cin>> u >> v >> w; // cout<< i <<" "; g[u].push_back({v,w}); g[v].push_back({u,w}); } // cout<<"SDFG"; dijkstra(Ss,'S'); dijkstra(U,'U'); dijkstra(V,'V'); for(int v = 1; v <= n; v++) for(auto e : g[v]) { int u = e.F, w = e.S; if(dis[v] == dis[u] + w) g2[u].push_back(v); } dfs(Ss); cout<< ans; } /* 6 6 1 6 1 4 1 2 1 2 3 1 3 5 1 2 4 3 4 5 2 5 6 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...